Author: markt
Date: Tue Mar 19 23:14:59 2013
New Revision: 1458566

URL: http://svn.apache.org/r1458566
Log:
Update Commons Fileupload to r1458500

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/   (props 
changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/package-info.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/Base64Decoder.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/MimeUtility.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1458564-1458565

Propchange: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/
------------------------------------------------------------------------------
  Merged 
/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload:r1458081-1458500
  Merged 
/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload:r1458564-1458565

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
 Tue Mar 19 23:14:59 2013
@@ -299,9 +299,8 @@ public abstract class FileUploadBase {
                 } catch (FileUploadIOException e) {
                     throw (FileUploadException) e.getCause();
                 } catch (IOException e) {
-                    throw new IOFileUploadException(
-                            String.format("Processing of %s request failed. 
%s",
-                                    MULTIPART_FORM_DATA, e.getMessage()), e);
+                    throw new IOFileUploadException(String.format("Processing 
of %s request failed. %s",
+                                                           
MULTIPART_FORM_DATA, e.getMessage()), e);
                 }
                 final FileItemHeaders fih = item.getHeaders();
                 fileItem.setHeaders(fih);

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/package-info.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/package-info.java?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/package-info.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/package-info.java
 Tue Mar 19 23:14:59 2013
@@ -18,7 +18,7 @@
 
 /**
  * <p><b>NOTE:</b> This code has been copied from commons-fileupload trunk
- * revision 1458080 and commons-io 1.4 and package renamed to avoid clashes 
with
+ * revision 1458500 and commons-io 1.4 and package renamed to avoid clashes 
with
  * any web apps that may wish to use these libraries.
  * </p>
  * <p>

Propchange: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/Base64Decoder.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/Base64Decoder.java?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/Base64Decoder.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/Base64Decoder.java
 Tue Mar 19 23:14:59 2013
@@ -82,17 +82,19 @@ final class Base64Decoder {
      * whitespace characters will be ignored.
      *
      * @param data the buffer containing the Base64-encoded data
-     * @param off the start offset (zero-based)
-     * @param length the number of bytes to convert
      * @param out the output stream to hold the decoded bytes
      *
      * @return the number of bytes produced.
      */
-    public static int decode(byte[] data, int off, int length, OutputStream 
out) throws IOException {
+    public static int decode(byte[] data, OutputStream out) throws IOException 
{
         byte    b1, b2, b3, b4;
         int        outLen = 0;
 
-        int        end = off + length;
+        if (data.length == 0) {
+            return outLen;
+        }
+
+        int        end = data.length;
 
         while (end > 0) {
             if (!ignore((char) data[end - 1])) {
@@ -102,7 +104,7 @@ final class Base64Decoder {
             end--;
         }
 
-        int  i = off;
+        int  i = 0;
         // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
         int  finish = end - 4; // last set of 4 bytes might include padding
 
@@ -159,11 +161,12 @@ final class Base64Decoder {
             // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
             out.write((b2 << 4) | (b3 >> 2)); // 4 bits of b2 plus 4 bits of b3
             outLen++;
-        } else if (p2 != PADDING) { // Nothing more to do if p2 == PADDING
-            b4 = DECODING_TABLE[p2];
-            // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
-            out.write((b3 << 6) | b4);        // 2 bits of b3 plus 6 bits of b4
-            outLen++;
+            if (p2 != PADDING) { // Nothing more to do if p2 == PADDING
+                b4 = DECODING_TABLE[p2];
+                // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
+                out.write((b3 << 6) | b4);        // 2 bits of b3 plus 6 bits 
of b4
+                outLen++;
+            }
         }
 
         return outLen;

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/MimeUtility.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/MimeUtility.java?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/MimeUtility.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/MimeUtility.java
 Tue Mar 19 23:14:59 2013
@@ -31,11 +31,31 @@ import java.util.Map;
 public final class MimeUtility {
 
     /**
+     * The {@code US-ASCII} charset identifier constant.
+     */
+    private static final String US_ASCII_CHARSET = "US-ASCII";
+
+    /**
+     * The marker to indicate text is encoded with BASE64 algorithm.
+     */
+    private static final String BASE64_ENCODING_MARKER = "B";
+
+    /**
+     * The marker to indicate text is encoded with QuotedPrintable algorithm.
+     */
+    private static final String QUOTEDPRINTABLE_ENCODING_MARKER = "Q";
+
+    /**
      * If the text contains any encoded tokens, those tokens will be marked 
with "=?".
      */
     private static final String ENCODED_TOKEN_MARKER = "=?";
 
     /**
+     * If the text contains any encoded tokens, those tokens will terminate 
with "=?".
+     */
+    private static final String ENCODED_TOKEN_FINISHER = "?=";
+
+    /**
      * The linear whitespace chars sequence.
      */
     private static final String LINEAR_WHITESPACE = " \t\r\n";
@@ -98,12 +118,12 @@ public final class MimeUtility {
             char ch = text.charAt(offset);
 
             // is this a whitespace character?
-            if (LINEAR_WHITESPACE.indexOf(ch) != -1) {
+            if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace found
                 startWhiteSpace = offset;
                 while (offset < endOffset) {
                     // step over the white space characters.
                     ch = text.charAt(offset);
-                    if (LINEAR_WHITESPACE.indexOf(ch) != -1) {
+                    if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace 
found
                         offset++;
                     } else {
                         // record the location of the first non lwsp and drop 
down to process the
@@ -117,9 +137,9 @@ public final class MimeUtility {
                 int wordStart = offset;
 
                 while (offset < endOffset) {
-                    // step over the white space characters.
+                    // step over the non white space characters.
                     ch = text.charAt(offset);
-                    if (LINEAR_WHITESPACE.indexOf(ch) == -1) {
+                    if (LINEAR_WHITESPACE.indexOf(ch) == -1) { // not white 
space
                         offset++;
                     } else {
                         break;
@@ -204,7 +224,7 @@ public final class MimeUtility {
         String encoding = word.substring(charsetPos + 1, encodingPos);
 
         // and finally the encoded text.
-        int encodedTextPos = word.indexOf("?=", encodingPos + 1);
+        int encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos 
+ 1);
         if (encodedTextPos == -1) {
             throw new ParseException("Missing encoded text in RFC 2047 
encoded-word: " + word);
         }
@@ -220,13 +240,13 @@ public final class MimeUtility {
             // the decoder writes directly to an output stream.
             ByteArrayOutputStream out = new 
ByteArrayOutputStream(encodedText.length());
 
-            byte[] encodedData = encodedText.getBytes("US-ASCII");
+            byte[] encodedData = encodedText.getBytes(US_ASCII_CHARSET);
 
             // Base64 encoded?
-            if (encoding.equals("B")) {
-                Base64Decoder.decode(encodedData, 0, encodedData.length, out);
-            } else if (encoding.equals("Q")) { // maybe quoted printable.
-                QuotedPrintableDecoder.decode(encodedData, 0, 
encodedData.length, out);
+            if (encoding.equals(BASE64_ENCODING_MARKER)) {
+                Base64Decoder.decode(encodedData, out);
+            } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // 
maybe quoted printable.
+                QuotedPrintableDecoder.decode(encodedData, out);
             } else {
                 throw new UnsupportedEncodingException("Unknown RFC 2047 
encoding: " + encoding);
             }

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java
 Tue Mar 19 23:14:59 2013
@@ -25,34 +25,12 @@ import java.io.OutputStream;
 final class QuotedPrintableDecoder {
 
     /**
-     * Set up the encoding table.
-     */
-    private static final byte[] ENCODING_TABLE = {
-        (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) 
'5', (byte) '6', (byte) '7',
-        (byte) '8', (byte) '9', (byte) 'A', (byte) 'B', (byte) 'C', (byte) 
'D', (byte) 'E', (byte) 'F'
-    };
-
-    /**
      * The shift value required to create the upper nibble
      * from the first of 2 byte values converted from ascii hex.
      */
     private static final int UPPER_NIBBLE_SHIFT = Byte.SIZE / 2;
 
     /**
-     * Set up the decoding table; this is indexed by a byte converted to an 
int,
-     * so must be at least as large as the number of different byte values,
-     * positive and negative and zero.
-     */
-    private static final byte[] DECODING_TABLE = new byte[Byte.MAX_VALUE - 
Byte.MIN_VALUE + 1];
-
-    static {
-        // initialize the decoding table
-        for (int i = 0; i < ENCODING_TABLE.length; i++) {
-            DECODING_TABLE[ENCODING_TABLE[i]] = (byte) i;
-        }
-    }
-
-    /**
      * Hidden constructor, this class must not be instantiated.
      */
     private QuotedPrintableDecoder() {
@@ -63,14 +41,14 @@ final class QuotedPrintableDecoder {
      * Decode the encoded byte data writing it to the given output stream.
      *
      * @param data   The array of byte data to decode.
-     * @param off    Starting offset within the array.
-     * @param length The length of data to encode.
      * @param out    The output stream used to return the decoded data.
      *
      * @return the number of bytes produced.
      * @exception IOException
      */
-    public static int decode(byte[] data, int off, int length, OutputStream 
out) throws IOException {
+    public static int decode(byte[] data, OutputStream out) throws IOException 
{
+        int off = 0;
+        int length = data.length;
         int endOffset = off + length;
         int bytesWritten = 0;
 
@@ -84,23 +62,23 @@ final class QuotedPrintableDecoder {
                 // we found an encoded character.  Reduce the 3 char sequence 
to one.
                 // but first, make sure we have two characters to work with.
                 if (off + 1 >= endOffset) {
-                    throw new IOException("Invalid quoted printable encoding");
+                    throw new IOException("Invalid quoted printable encoding; 
truncated escape sequence");
                 }
-                // convert the two bytes back from hex.
+
                 byte b1 = data[off++];
                 byte b2 = data[off++];
 
                 // we've found an encoded carriage return.  The next char 
needs to be a newline
                 if (b1 == '\r') {
                     if (b2 != '\n') {
-                        throw new IOException("Invalid quoted printable 
encoding");
+                        throw new IOException("Invalid quoted printable 
encoding; CR must be followed by LF");
                     }
                     // this was a soft linebreak inserted by the encoding.  We 
just toss this away
                     // on decode.
                 } else {
                     // this is a hex pair we need to convert back to a single 
byte.
-                    byte c1 = DECODING_TABLE[b1];
-                    byte c2 = DECODING_TABLE[b2];
+                    int c1 = hexToBinary(b1);
+                    int c2 = hexToBinary(b2);
                     out.write((c1 << UPPER_NIBBLE_SHIFT) | c2);
                     // 3 bytes in, one byte out
                     bytesWritten++;
@@ -115,4 +93,20 @@ final class QuotedPrintableDecoder {
         return bytesWritten;
     }
 
+    /**
+     * Convert a hex digit to the binary value it represents.
+     *
+     * @param b the ascii hex byte to convert (0-0, A-F, a-f)
+     * @return the int value of the hex byte, 0-15
+     * @throws IOException if the byte is not a valid hex digit.
+     */
+    private static int hexToBinary(final byte b) throws IOException {
+        // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
+        final int i = Character.digit((char) b, 16);
+        if (i == -1) {
+            throw new IOException("Invalid quoted printable encoding: not a 
valid hex digit: " + b);
+        }
+        return i;
+    }
+
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1458566&r1=1458565&r2=1458566&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Mar 19 23:14:59 2013
@@ -79,7 +79,7 @@
       </add>
       <update>
         Update Tomcat's internal copy of Commons FileUpload to FileUpload 
trunk,
-        revision 1458080 and the associated extract from Commons IO to 2.4.
+        revision 1458500 and the associated extract from Commons IO to 2.4.
         (markt)
       </update>
       <fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to