Author: markt
Date: Fri Mar 15 10:21:16 2013
New Revision: 1456863
URL: http://svn.apache.org/r1456863
Log:
Merge updates from Commons FileUpload to r1453202
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ (props changed)
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ProgressListener.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
Propchange: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/
------------------------------------------------------------------------------
Merged
/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload:r1453030-1453202
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
Fri Mar 15 10:21:16 2013
@@ -446,8 +446,7 @@ public abstract class FileUploadBase {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
- Map<String,String> params =
- parser.parse(pContentDisposition, ';');
+ Map<String,String> params = parser.parse(pContentDisposition, ';');
fieldName = params.get("name");
if (fieldName != null) {
fieldName = fieldName.trim();
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
Fri Mar 15 10:21:16 2013
@@ -86,25 +86,36 @@ import org.apache.tomcat.util.http.fileu
* @version $Id$
*/
public class MultipartStream {
+
/**
* Internal class, which is used to invoke the
* {@link ProgressListener}.
*/
public static class ProgressNotifier {
- /** The listener to invoke.
+ /**
+ * The listener to invoke.
*/
private final ProgressListener listener;
- /** Number of expected bytes, if known, or -1.
+
+ /**
+ * Number of expected bytes, if known, or -1.
*/
private final long contentLength;
- /** Number of bytes, which have been read so far.
+
+ /**
+ * Number of bytes, which have been read so far.
*/
private long bytesRead;
- /** Number of items, which have been read so far.
+
+ /**
+ * Number of items, which have been read so far.
*/
private int items;
- /** Creates a new instance with the given listener
+
+ /**
+ * Creates a new instance with the given listener
* and content length.
+ *
* @param pListener The listener to invoke.
* @param pContentLength The expected content length.
*/
@@ -112,7 +123,10 @@ public class MultipartStream {
listener = pListener;
contentLength = pContentLength;
}
- /** Called to indicate that bytes have been read.
+
+ /**
+ * Called to indicate that bytes have been read.
+ *
* @param pBytes Number of bytes, which have been read.
*/
void noteBytesRead(int pBytes) {
@@ -122,126 +136,110 @@ public class MultipartStream {
bytesRead += pBytes;
notifyListener();
}
- /** Called to indicate, that a new file item has been detected.
+
+ /**
+ * Called to indicate, that a new file item has been detected.
*/
void noteItem() {
++items;
notifyListener();
}
- /** Called for notifying the listener.
+
+ /**
+ * Called for notifying the listener.
*/
private void notifyListener() {
if (listener != null) {
listener.update(bytesRead, contentLength, items);
}
}
+
}
// ----------------------------------------------------- Manifest constants
-
/**
* The Carriage Return ASCII character value.
*/
public static final byte CR = 0x0D;
-
/**
* The Line Feed ASCII character value.
*/
public static final byte LF = 0x0A;
-
/**
* The dash (-) ASCII character value.
*/
public static final byte DASH = 0x2D;
-
/**
* The maximum length of <code>header-part</code> that will be
* processed (10 kilobytes = 10240 bytes.).
*/
public static final int HEADER_PART_SIZE_MAX = 10240;
-
/**
* The default length of the buffer used for processing a request.
*/
protected static final int DEFAULT_BUFSIZE = 4096;
-
/**
* A byte sequence that marks the end of <code>header-part</code>
* (<code>CRLFCRLF</code>).
*/
- protected static final byte[] HEADER_SEPARATOR = {
- CR, LF, CR, LF };
-
+ protected static final byte[] HEADER_SEPARATOR = { CR, LF, CR, LF };
/**
* A byte sequence that that follows a delimiter that will be
* followed by an encapsulation (<code>CRLF</code>).
*/
- protected static final byte[] FIELD_SEPARATOR = {
- CR, LF};
-
+ protected static final byte[] FIELD_SEPARATOR = { CR, LF};
/**
* A byte sequence that that follows a delimiter of the last
* encapsulation in the stream (<code>--</code>).
*/
- protected static final byte[] STREAM_TERMINATOR = {
- DASH, DASH};
-
+ protected static final byte[] STREAM_TERMINATOR = { DASH, DASH};
/**
* A byte sequence that precedes a boundary (<code>CRLF--</code>).
*/
- protected static final byte[] BOUNDARY_PREFIX = {
- CR, LF, DASH, DASH};
-
+ protected static final byte[] BOUNDARY_PREFIX = { CR, LF, DASH, DASH};
// ----------------------------------------------------------- Data members
-
/**
* The input stream from which data is read.
*/
private final InputStream input;
-
/**
* The length of the boundary token plus the leading <code>CRLF--</code>.
*/
private int boundaryLength;
-
/**
* The amount of data, in bytes, that must be kept in the buffer in order
* to detect delimiters reliably.
*/
private int keepRegion;
-
/**
* The byte sequence that partitions the stream.
*/
private byte[] boundary;
-
/**
* The length of the buffer used for processing the request.
*/
private final int bufSize;
-
/**
* The buffer used for processing the request.
*/
private final byte[] buffer;
-
/**
* The index of first valid character in the buffer.
* <br>
@@ -249,7 +247,6 @@ public class MultipartStream {
*/
private int head;
-
/**
* The index of last valid character in the buffer + 1.
* <br>
@@ -257,13 +254,11 @@ public class MultipartStream {
*/
private int tail;
-
/**
* The content encoding to use when reading headers.
*/
private String headerEncoding;
-
/**
* The progress notifier, if any, or null.
*/
@@ -312,7 +307,6 @@ public class MultipartStream {
tail = 0;
}
-
/**
* <p> Constructs a <code>MultipartStream</code> with a default size
buffer.
*
@@ -333,12 +327,10 @@ public class MultipartStream {
// --------------------------------------------------------- Public methods
-
/**
* Retrieves the character encoding used when reading the headers of an
* individual part. When not specified, or <code>null</code>, the platform
* default encoding is used.
-
*
* @return The encoding used to read part headers.
*/
@@ -346,7 +338,6 @@ public class MultipartStream {
return headerEncoding;
}
-
/**
* Specifies the character encoding to be used when reading the headers of
* individual parts. When not specified, or <code>null</code>, the platform
@@ -358,7 +349,6 @@ public class MultipartStream {
headerEncoding = encoding;
}
-
/**
* Reads a byte from the <code>buffer</code>, and refills it as
* necessary.
@@ -384,7 +374,6 @@ public class MultipartStream {
return buffer[head++];
}
-
/**
* Skips a <code>boundary</code> token, and checks whether more
* <code>encapsulations</code> are contained in the stream.
@@ -428,7 +417,6 @@ public class MultipartStream {
return nextChunk;
}
-
/**
* <p>Changes the boundary token used for partitioning the stream.
*
@@ -458,7 +446,6 @@ public class MultipartStream {
boundary.length);
}
-
/**
* <p>Reads the <code>header-part</code> of the current
* <code>encapsulation</code>.
@@ -474,8 +461,7 @@ public class MultipartStream {
*
* @throws MalformedStreamException if the stream ends unexpecetedly.
*/
- public String readHeaders()
- throws MalformedStreamException {
+ public String readHeaders() throws MalformedStreamException {
int i = 0;
byte b;
// to support multi-byte characters
@@ -516,7 +502,6 @@ public class MultipartStream {
return headers;
}
-
/**
* <p>Reads <code>body-data</code> from the current
* <code>encapsulation</code> and writes its contents into the
@@ -562,13 +547,10 @@ public class MultipartStream {
* @throws MalformedStreamException if the stream ends unexpectedly.
* @throws IOException if an i/o error occurs.
*/
- public int discardBodyData()
- throws MalformedStreamException,
- IOException {
+ public int discardBodyData() throws MalformedStreamException, IOException {
return readBodyData(null);
}
-
/**
* Finds the beginning of the first <code>encapsulation</code>.
*
@@ -577,8 +559,7 @@ public class MultipartStream {
*
* @throws IOException if an i/o error occurs.
*/
- public boolean skipPreamble()
- throws IOException {
+ public boolean skipPreamble() throws IOException {
// First delimiter may be not preceeded with a CRLF.
System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2);
boundaryLength = boundary.length - 2;
@@ -600,7 +581,6 @@ public class MultipartStream {
}
}
-
/**
* Compares <code>count</code> first bytes in the arrays
* <code>a</code> and <code>b</code>.
@@ -623,7 +603,6 @@ public class MultipartStream {
return true;
}
-
/**
* Searches for a byte of specified value in the <code>buffer</code>,
* starting at the specified <code>position</code>.
@@ -645,7 +624,6 @@ public class MultipartStream {
return -1;
}
-
/**
* Searches for the <code>boundary</code> in the <code>buffer</code>
* region delimited by <code>head</code> and <code>tail</code>.
@@ -681,10 +659,12 @@ public class MultipartStream {
* Thrown to indicate that the input stream fails to follow the
* required syntax.
*/
- public static class MalformedStreamException
- extends IOException {
+ public static class MalformedStreamException extends IOException {
- private static final long serialVersionUID = 1L;
+ /**
+ * The UID to use when serializing this instance.
+ */
+ private static final long serialVersionUID = 6466926458059796677L;
/**
* Constructs a <code>MalformedStreamException</code> with no
@@ -703,16 +683,19 @@ public class MultipartStream {
public MalformedStreamException(String message) {
super(message);
}
- }
+ }
/**
* Thrown upon attempt of setting an invalid boundary token.
*/
- public static class IllegalBoundaryException
- extends IOException {
+ public static class IllegalBoundaryException extends IOException {
- private static final long serialVersionUID = 1L;
+
+ /**
+ * The UID to use when serializing this instance.
+ */
+ private static final long serialVersionUID = -161533165102632918L;
/**
* Constructs an <code>IllegalBoundaryException</code> with no
@@ -731,23 +714,32 @@ public class MultipartStream {
public IllegalBoundaryException(String message) {
super(message);
}
+
}
/**
* An {@link InputStream} for reading an items contents.
*/
public class ItemInputStream extends InputStream implements Closeable {
- /** The number of bytes, which have been read so far.
+
+ /**
+ * The number of bytes, which have been read so far.
*/
private long total;
- /** The number of bytes, which must be hold, because
+
+ /**
+ * The number of bytes, which must be hold, because
* they might be a part of the boundary.
*/
private int pad;
- /** The current offset in the buffer.
+
+ /**
+ * The current offset in the buffer.
*/
private int pos;
- /** Whether the stream is already closed.
+
+ /**
+ * Whether the stream is already closed.
*/
private boolean closed;
@@ -775,6 +767,7 @@ public class MultipartStream {
/**
* Returns the number of bytes, which have been read
* by the stream.
+ *
* @return Number of bytes, which have been read so far.
*/
public long getBytesRead() {
@@ -784,6 +777,7 @@ public class MultipartStream {
/**
* Returns the number of bytes, which are currently
* available, without blocking.
+ *
* @throws IOException An I/O error occurs.
* @return Number of bytes in the buffer.
*/
@@ -795,12 +789,14 @@ public class MultipartStream {
return pos - head;
}
- /** Offset when converting negative bytes to integers.
+ /**
+ * Offset when converting negative bytes to integers.
*/
private static final int BYTE_POSITIVE_OFFSET = 256;
/**
* Returns the next byte in the stream.
+ *
* @return The next byte in the stream, as a non-negative
* integer, or -1 for EOF.
* @throws IOException An I/O error occurred.
@@ -825,6 +821,7 @@ public class MultipartStream {
/**
* Reads bytes into the given buffer.
+ *
* @param b The destination buffer, where to write to.
* @param off Offset of the first byte in the buffer.
* @param len Maximum number of bytes to read.
@@ -856,6 +853,7 @@ public class MultipartStream {
/**
* Closes the input stream.
+ *
* @throws IOException An I/O error occurred.
*/
@Override
@@ -865,6 +863,7 @@ public class MultipartStream {
/**
* Closes the input stream.
+ *
* @param pCloseUnderlying Whether to close the underlying stream
* (hard close)
* @throws IOException An I/O error occurred.
@@ -893,6 +892,7 @@ public class MultipartStream {
/**
* Skips the given number of bytes.
+ *
* @param bytes Number of bytes to skip.
* @return The number of bytes, which have actually been
* skipped.
@@ -917,6 +917,7 @@ public class MultipartStream {
/**
* Attempts to read more data.
+ *
* @return Number of available bytes
* @throws IOException An I/O error occurred.
*/
@@ -958,11 +959,14 @@ public class MultipartStream {
/**
* Returns, whether the stream is closed.
+ *
* @return True, if the stream is closed, otherwise false.
*/
@Override
public boolean isClosed() {
return closed;
}
+
}
+
}
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java
Fri Mar 15 10:21:16 2013
@@ -22,7 +22,8 @@ import java.util.Map;
/**
* A simple parser intended to parse sequences of name/value pairs.
- * Parameter values are exptected to be enclosed in quotes if they
+ *
+ * Parameter values are expected to be enclosed in quotes if they
* contain unsafe characters, such as '=' characters or separators.
* Parameter values are optional and can be omitted.
*
@@ -32,8 +33,8 @@ import java.util.Map;
*
* @author <a href="mailto:[email protected]">Oleg Kalnichevski</a>
*/
-
public class ParameterParser {
+
/**
* String to be parsed.
*/
@@ -327,4 +328,5 @@ public class ParameterParser {
}
return params;
}
+
}
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ProgressListener.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ProgressListener.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ProgressListener.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ProgressListener.java
Fri Mar 15 10:21:16 2013
@@ -16,13 +16,15 @@
*/
package org.apache.tomcat.util.http.fileupload;
-
/**
* The {@link ProgressListener} may be used to display a progress bar
* or do stuff like that.
*/
public interface ProgressListener {
- /** Updates the listeners status information.
+
+ /**
+ * Updates the listeners status information.
+ *
* @param pBytesRead The total number of bytes, which have been read
* so far.
* @param pContentLength The total number of bytes, which are being
@@ -31,4 +33,5 @@ public interface ProgressListener {
* read. (0 = no item so far, 1 = first item is being read, ...)
*/
void update(long pBytesRead, long pContentLength, int pItems);
+
}
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/RequestContext.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/RequestContext.java
Fri Mar 15 10:21:16 2013
@@ -61,4 +61,5 @@ public interface RequestContext {
* @throws IOException if a problem occurs.
*/
InputStream getInputStream() throws IOException;
+
}
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
Fri Mar 15 10:21:16 2013
@@ -17,12 +17,10 @@
package org.apache.tomcat.util.http.fileupload.servlet;
import java.io.IOException;
-import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
-import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileItemFactory;
import org.apache.tomcat.util.http.fileupload.FileItemIterator;
import org.apache.tomcat.util.http.fileupload.FileUpload;
@@ -35,9 +33,9 @@ import org.apache.tomcat.util.http.fileu
* <p>This class handles multiple files per single HTML widget, sent using
* <code>multipart/mixed</code> encoding type, as specified by
* <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
- * #parseRequest(HttpServletRequest)} to acquire a list of {@link
- * org.apache.tomcat.util.http.fileupload.FileItem}s associated with a given
HTML
- * widget.</p>
+ * #parseRequest(org.apache.tomcat.util.http.fileupload.RequestContext)} to
+ * acquire a list of {@link org.apache.tomcat.util.http.fileupload.FileItem}s
+ * associated with a given HTML widget.</p>
*
* <p>How the data for individual parts is stored is determined by the factory
* used to create them; a given part may be in memory, on disk, or somewhere
@@ -118,24 +116,6 @@ public class ServletFileUpload extends F
*
* @param request The servlet request to be parsed.
*
- * @return A list of <code>FileItem</code> instances parsed from the
- * request, in the order that they were transmitted.
- *
- * @throws FileUploadException if there are problems reading/parsing
- * the request or storing files.
- */
- public List<FileItem> parseRequest(HttpServletRequest request)
- throws FileUploadException {
- return parseRequest(new ServletRequestContext(request));
- }
-
-
- /**
- * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
- * compliant <code>multipart/form-data</code> stream.
- *
- * @param request The servlet request to be parsed.
- *
* @return An iterator to instances of <code>FileItemStream</code>
* parsed from the request, in the order that they were
* transmitted.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java?rev=1456863&r1=1456862&r2=1456863&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/util/FileItemHeadersImpl.java
Fri Mar 15 10:21:16 2013
@@ -19,8 +19,8 @@ package org.apache.tomcat.util.http.file
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -42,14 +42,7 @@ public class FileItemHeadersImpl impleme
* <code>String</code> instances.
*/
private final Map<String,List<String>> headerNameToValueListMap =
- new HashMap<>();
-
- /**
- * List to preserve order of headers as added. This would not be
- * needed if a <code>LinkedHashMap</code> could be used, but don't
- * want to depend on 1.4.
- */
- private final List<String> headerNameList = new ArrayList<>();
+ new LinkedHashMap<>();
@Override
public String getHeader(String name) {
@@ -63,7 +56,7 @@ public class FileItemHeadersImpl impleme
@Override
public Iterator<String> getHeaderNames() {
- return headerNameList.iterator();
+ return headerNameToValueListMap.keySet().iterator();
}
@Override
@@ -71,7 +64,7 @@ public class FileItemHeadersImpl impleme
String nameLower = name.toLowerCase(Locale.ENGLISH);
List<String> headerValueList = headerNameToValueListMap.get(nameLower);
if (null == headerValueList) {
- return Collections.<String>emptyList().iterator();
+ headerValueList = Collections.emptyList();
}
return headerValueList.iterator();
}
@@ -88,7 +81,6 @@ public class FileItemHeadersImpl impleme
if (null == headerValueList) {
headerValueList = new ArrayList<>();
headerNameToValueListMap.put(nameLower, headerValueList);
- headerNameList.add(nameLower);
}
headerValueList.add(value);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]