Author: markt
Date: Tue Mar 19 10:13:17 2013
New Revision: 1458206
URL: http://svn.apache.org/r1458206
Log:
Update Fileupload
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/FileItem.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/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:r1458187,1458192,1458200
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:r1456913-1456917,1456919-1458080
Merged
/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload:r1458187,1458192,1458200
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileItem.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileItem.java?rev=1458206&r1=1458205&r2=1458206&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileItem.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileItem.java
Tue Mar 19 10:13:17 2013
@@ -197,7 +197,7 @@ public interface FileItem extends Serial
* be used for storing the contents of the file.
*
* @return An {@link java.io.OutputStream OutputStream} that can be used
- * for storing the contents of the file.
+ * for storing the contensts of the file.
*
* @throws IOException if an error occurs.
*/
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=1458206&r1=1458205&r2=1458206&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 10:13:17 2013
@@ -18,7 +18,7 @@
/**
* <p><b>NOTE:</b> This code has been copied from commons-fileupload trunk
- * revision 1456918 and commons-io 1.4 and package renamed to avoid clashes
with
+ * revision 1458080 and commons-io 1.4 and package renamed to avoid clashes
with
* any web apps that may wish to use these libraries.
* </p>
* <p>
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=1458206&r1=1458205&r2=1458206&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 10:13:17 2013
@@ -25,7 +25,7 @@ import java.io.OutputStream;
final class Base64Decoder {
/**
- * set up the encoding table.
+ * Set up the encoding table.
*/
private static final byte[] ENCODING_TABLE = {
(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte)
'F', (byte) 'G',
@@ -35,8 +35,7 @@ final class Base64Decoder {
(byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte)
'f', (byte) 'g',
(byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', (byte) 'l', (byte)
'm', (byte) 'n',
(byte) 'o', (byte) 'p', (byte) 'q', (byte) 'r', (byte) 's', (byte)
't', (byte) 'u',
- (byte) 'v',
- (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z',
+ (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z',
(byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte)
'5', (byte) '6',
(byte) '7', (byte) '8', (byte) '9',
(byte) '+', (byte) '/'
@@ -48,14 +47,11 @@ final class Base64Decoder {
private static final byte PADDING = (byte) '=';
/**
- * the decoding table size.
+ * 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 int DECODING_TABLE_SIZE = 256;
-
- /**
- * set up the decoding table.
- */
- private static final byte[] DECODING_TABLE = new byte[DECODING_TABLE_SIZE];
+ private static final byte[] DECODING_TABLE = new byte[Byte.MAX_VALUE -
Byte.MIN_VALUE + 1];
static {
for (int i = 0; i < ENCODING_TABLE.length; i++) {
@@ -72,27 +68,27 @@ final class Base64Decoder {
/**
* Checks if the input char must be skipped from the decode.
+ * The method skips whitespace characters LF, CR, horizontal tab and space.
*
- * @param c the char has to be checked.
- * @return true, if the input char has to be checked, false otherwise.
+ * @param c the char to be checked.
+ * @return true, if the input char has to be skipped, false otherwise.
*/
- private static boolean ignore(
- char c) {
+ private static boolean ignore(char c) {
return (c == '\n' || c == '\r' || c == '\t' || c == ' ');
}
/**
- * decode the base 64 encoded byte data writing it to the given output
stream,
+ * Decode the base 64 encoded byte data writing it to the given output
stream,
* 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, int off, int length, OutputStream
out) throws IOException {
byte b1, b2, b3, b4;
int outLen = 0;
@@ -107,7 +103,8 @@ final class Base64Decoder {
}
int i = off;
- int finish = end - 4;
+ // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
+ int finish = end - 4; // last set of 4 bytes might include padding
while (i < finish) {
while ((i < finish) && ignore((char) data[i])) {
@@ -134,40 +131,39 @@ final class Base64Decoder {
b4 = DECODING_TABLE[data[i++]];
- out.write((b1 << 2) | (b2 >> 4));
- out.write((b2 << 4) | (b3 >> 2));
- out.write((b3 << 6) | b4);
+ // Convert 4 6-bit bytes to 3 8-bit bytes
+ // CHECKSTYLE IGNORE MagicNumber FOR NEXT 3 LINES
+ out.write((b1 << 2) | (b2 >> 4)); // 6 bits of b1 plus 2 bits of b2
+ out.write((b2 << 4) | (b3 >> 2)); // 4 bits of b2 plus 4 bits of b3
+ out.write((b3 << 6) | b4); // 2 bits of b3 plus 6 bits of b4
+ // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
outLen += 3;
}
- if (data[end - 2] == PADDING) {
- b1 = DECODING_TABLE[data[end - 4]];
- b2 = DECODING_TABLE[data[end - 3]];
-
- out.write((b1 << 2) | (b2 >> 4));
-
- outLen += 1;
- } else if (data[end - 1] == PADDING) {
- b1 = DECODING_TABLE[data[end - 4]];
- b2 = DECODING_TABLE[data[end - 3]];
- b3 = DECODING_TABLE[data[end - 2]];
-
- out.write((b1 << 2) | (b2 >> 4));
- out.write((b2 << 4) | (b3 >> 2));
-
- outLen += 2;
- } else {
- b1 = DECODING_TABLE[data[end - 4]];
- b2 = DECODING_TABLE[data[end - 3]];
- b3 = DECODING_TABLE[data[end - 2]];
- b4 = DECODING_TABLE[data[end - 1]];
-
- out.write((b1 << 2) | (b2 >> 4));
- out.write((b2 << 4) | (b3 >> 2));
- out.write((b3 << 6) | b4);
-
- outLen += 3;
+ // Get the last 4 bytes; only last two can be padding
+ b1 = DECODING_TABLE[data[i++]];
+ b2 = DECODING_TABLE[data[i++]];
+
+ // always write the first byte
+ // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE
+ out.write((b1 << 2) | (b2 >> 4)); // 6 bits of b1 plus 2 bits of b2
+ outLen++;
+
+ byte p1 = data[i++];
+ byte p2 = data[i++];
+
+ b3 = DECODING_TABLE[p1]; // may be needed later
+
+ if (p1 != PADDING) { // Nothing more to do if p1 == PADDING
+ // 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++;
}
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=1458206&r1=1458205&r2=1458206&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 10:13:17 2013
@@ -31,6 +31,11 @@ import java.util.Map;
public final class MimeUtility {
/**
+ * If the text contains any encoded tokens, those tokens will be marked
with "=?".
+ */
+ private static final String ENCODED_TOKEN_MARKER = "=?";
+
+ /**
* The linear whitespace chars sequence.
*/
private static final String LINEAR_WHITESPACE = " \t\r\n";
@@ -63,19 +68,19 @@ public final class MimeUtility {
/**
* Decode a string of text obtained from a mail header into
- * it's proper form. The text generally will consist of a
+ * its proper form. The text generally will consist of a
* string of tokens, some of which may be encoded using
* base64 encoding.
*
* @param text The text to decode.
*
- * @return The decoded test string.
- * @throws UnsupportedEncodingException
+ * @return The decoded text string.
+ * @throws UnsupportedEncodingException if the detected encoding in the
input text is not supported.
*/
public static String decodeText(String text) throws
UnsupportedEncodingException {
// if the text contains any encoded tokens, those tokens will be
marked with "=?". If the
// source string doesn't contain that sequent, no decoding is required.
- if (text.indexOf("=?") < 0) {
+ if (text.indexOf(ENCODED_TOKEN_MARKER) < 0) {
return text;
}
@@ -85,7 +90,7 @@ public final class MimeUtility {
int startWhiteSpace = -1;
int endWhiteSpace = -1;
- StringBuffer decodedText = new StringBuffer(text.length());
+ StringBuilder decodedText = new StringBuilder(text.length());
boolean previousTokenEncoded = false;
@@ -125,7 +130,7 @@ public final class MimeUtility {
// pull out the word token.
String word = text.substring(wordStart, offset);
// is the token encoded? decode the word
- if (word.startsWith("=?")) {
+ if (word.startsWith(ENCODED_TOKEN_MARKER)) {
try {
// if this gives a parsing failure, treat it like a
non-encoded word.
String decodedWord = decodeWord(word);
@@ -178,7 +183,7 @@ public final class MimeUtility {
// encoded words start with the characters "=?". If this not an
encoded word, we throw a
// ParseException for the caller.
- if (!word.startsWith("=?")) {
+ if (!word.startsWith(ENCODED_TOKEN_MARKER)) {
throw new ParseException("Invalid RFC 2047 encoded-word: " + word);
}
@@ -221,7 +226,7 @@ public final class MimeUtility {
if (encoding.equals("B")) {
Base64Decoder.decode(encodedData, 0, encodedData.length, out);
} else if (encoding.equals("Q")) { // maybe quoted printable.
- QuotedPrintableDecoder.decodeWord(encodedData, 0,
encodedData.length, out);
+ QuotedPrintableDecoder.decode(encodedData, 0,
encodedData.length, 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=1458206&r1=1458205&r2=1458206&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 10:13:17 2013
@@ -33,19 +33,17 @@ final class QuotedPrintableDecoder {
};
/**
- * The default number of byte shift for decode.
+ * The shift value required to create the upper nibble
+ * from the first of 2 byte values converted from ascii hex.
*/
- private static final int OUT_SHIFT = 4;
+ private static final int UPPER_NIBBLE_SHIFT = Byte.SIZE / 2;
/**
- * the decoding table size.
+ * 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 int DECODING_TABLE_SIZE = 128;
-
- /**
- * Set up the decoding table.
- */
- private static final byte[] DECODING_TABLE = new byte[DECODING_TABLE_SIZE];
+ private static final byte[] DECODING_TABLE = new byte[Byte.MAX_VALUE -
Byte.MIN_VALUE + 1];
static {
// initialize the decoding table
@@ -62,7 +60,7 @@ final class QuotedPrintableDecoder {
}
/**
- * Decode the unencoded byte data writing it to the given output stream.
+ * 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.
@@ -72,7 +70,7 @@ final class QuotedPrintableDecoder {
* @return the number of bytes produced.
* @exception IOException
*/
- public static int decodeWord(byte[] data, int off, int length,
OutputStream out) throws IOException {
+ public static int decode(byte[] data, int off, int length, OutputStream
out) throws IOException {
int endOffset = off + length;
int bytesWritten = 0;
@@ -103,7 +101,7 @@ final class QuotedPrintableDecoder {
// this is a hex pair we need to convert back to a single
byte.
byte c1 = DECODING_TABLE[b1];
byte c2 = DECODING_TABLE[b2];
- out.write((c1 << OUT_SHIFT) | c2);
+ out.write((c1 << UPPER_NIBBLE_SHIFT) | c2);
// 3 bytes in, one byte out
bytesWritten++;
}
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=1458206&r1=1458205&r2=1458206&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Mar 19 10:13:17 2013
@@ -79,7 +79,7 @@
</add>
<update>
Update Tomcat's internal copy of Commons FileUpload to FileUpload
trunk,
- revision 1456918 and the associated extract from Commons IO to 2.4.
+ revision 1458080 and the associated extract from Commons IO to 2.4.
(markt)
</update>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]