org.apache.struts.upload
Class MultipartIterator
java.lang.Object
org.apache.struts.upload.MultipartIterator
public class MultipartIterator
extends java.lang.Object
The MultipartIterator class is responsible for reading the
input data of a multipart request and splitting it up into
input elements, wrapped inside of a
MultipartElement
for easy definition. To use this class, create a new instance
of MultipartIterator passing it a HttpServletRequest in the
constructor. Then use the
getNextElement
method until it returns null, then you're finished. Example:
MultipartIterator iterator = new MultipartIterator(request);
MultipartElement element;
while ((element = iterator.getNextElement()) != null) {
//do something with element
}
MultipartIterator(HttpServletRequest request) - Constructs a MultipartIterator with a default buffer size and no file size
limit
|
MultipartIterator(HttpServletRequest request, int bufferSize) - Constructs a MultipartIterator with the specified buffer size and
no file size limit
|
MultipartIterator(HttpServletRequest request, int bufferSize, long maxSize) - Constructs a MultipartIterator with the specified buffer size and
the specified file size limit in bytes
|
MultipartIterator(HttpServletRequest request, int bufferSize, long maxSize, String tempDir)
|
DEFAULT_ENCODING
private static final String DEFAULT_ENCODING
The default encoding of a text element if none is specified.
FILE_PREFIX
private static final String FILE_PREFIX
HEADER_CONTENT_DISPOSITION
public static final String HEADER_CONTENT_DISPOSITION
The name of the Content-Disposition header.
HEADER_CONTENT_TYPE
public static String HEADER_CONTENT_TYPE
The name of the Content-Type header.
MESSAGE_CANNOT_RETRIEVE_BOUNDARY
public static final String MESSAGE_CANNOT_RETRIEVE_BOUNDARY
The exception message for when the boundary of a multipart request can't be determined.
PARAMETER_BOUNDARY
private static final String PARAMETER_BOUNDARY
TEXT_BUFFER_SIZE
private static final int TEXT_BUFFER_SIZE
The size in bytes to copy of text data at a time.
boundary
protected String boundary
The boundary for this multipart request
bufferSize
protected int bufferSize
The amount of data read from a request at a time.
This also represents the maximum size in bytes of
a line read from the request [4KB]
contentLength
protected int contentLength
The content length of this request
contentType
protected String contentType
The content-type.
diskBufferSize
protected int diskBufferSize
The size in bytes written to the filesystem at a time [20K]
maxLengthExceeded
protected boolean maxLengthExceeded
Whether the maximum length has been exceeded.
maxSize
protected long maxSize
The maximum file size in bytes allowed. Ignored if -1
request
protected HttpServletRequest request
The request instance for this class
tempDir
protected String tempDir
The temporary directory to store files
MultipartIterator
public MultipartIterator(HttpServletRequest request)
throws IOException
Constructs a MultipartIterator with a default buffer size and no file size
limit
request
- The multipart request to iterate
MultipartIterator
public MultipartIterator(HttpServletRequest request,
int bufferSize)
throws IOException
Constructs a MultipartIterator with the specified buffer size and
no file size limit
request
- The multipart request to iteratebufferSize
- The size in bytes that should be read from the input
stream at a times
MultipartIterator
public MultipartIterator(HttpServletRequest request,
int bufferSize,
long maxSize)
throws IOException
Constructs a MultipartIterator with the specified buffer size and
the specified file size limit in bytes
request
- The multipart request to iteratebufferSize
- The size in bytes that should be read from the input
stream at a timesmaxSize
- The maximum size in bytes allowed for a multipart element's data
MultipartIterator
public MultipartIterator(HttpServletRequest request,
int bufferSize,
long maxSize,
String tempDir)
throws IOException
createFileMultipartElement
protected MultipartElement createFileMultipartElement()
throws IOException
Create a multipart element instance representing the file in the stream.
createLocalFile
protected File createLocalFile()
throws IOException
Creates a file on disk from the current mulitpart element.
createTextMultipartElement
protected MultipartElement createTextMultipartElement(String encoding)
throws IOException
Create a text element from the data in the body of the element.
encoding
- The character encoding of the string.
getBoundaryFromContentType
private final void getBoundaryFromContentType()
throws IOException
Parses a content-type String for the boundary.
getBufferSize
public int getBufferSize()
Get the maximum amount of bytes read from a line at one time
javax.servlet.ServletInputStream.readLine(byte[], int, int)
getContentTypeOfRequest
private final void getContentTypeOfRequest()
Gets the value of the Content-Type header of the request.
getElementEncoding
protected String getElementEncoding()
Get the character encoding used for this current multipart element.
getMaxSize
public long getMaxSize()
Get the maximum post data size allowed for a multipart request
- The maximum post data size in bytes
getNextElement
public MultipartElement getNextElement()
throws IOException
Retrieves the next element in the iterator if one exists.
isMaxLengthExceeded
public boolean isMaxLengthExceeded()
Whether or not the maximum length has been exceeded by the client.
parseRequest
protected void parseRequest()
throws IOException
Handles retrieving the boundary and setting the input stream
setBufferSize
public void setBufferSize(int bufferSize)
Set the maximum amount of bytes read from a line at one time
javax.servlet.ServletInputStream.readLine(byte[], int, int)
setMaxSize
public void setMaxSize(long maxSize)
Set the maximum post data size allowed for a multipart request
maxSize
- The maximum post data size in bytes, set to -1
for no limit
Copyright B) 2000-2007 - The Apache Software Foundation