|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.apache.struts.upload.MultipartIterator
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
}
MultipartElement| Field Summary | |
protected java.lang.String |
boundary
The boundary for this multipart request |
protected byte[] |
boundaryBytes
The byte array representing the boundary for this multipart request |
protected int |
bufferSize
The amount of data read from a request at a time. |
protected int |
contentLength
The content length of this request |
protected boolean |
contentRead
Whether or not the input stream is finished |
protected int |
diskBufferSize
The size in bytes written to the filesystem at a time [20K] |
protected BufferedMultipartInputStream |
inputStream
The input stream instance for this class |
static int |
MAX_LINE_SIZE
The maximum size in bytes of the buffer used to read lines [4K] |
protected long |
maxSize
The maximum file size in bytes allowed. |
protected javax.servlet.http.HttpServletRequest |
request
The request instance for this class |
protected java.lang.String |
tempDir
The temporary directory to store files |
protected long |
totalLength
The total bytes read from this request |
| Constructor Summary | |
MultipartIterator(javax.servlet.http.HttpServletRequest request)
Constructs a MultipartIterator with a default buffer size and no file size limit |
|
MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize)
Constructs a MultipartIterator with the specified buffer size and no file size limit |
|
MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize,
long maxSize)
Constructs a MultipartIterator with the specified buffer size and the specified file size limit in bytes |
|
MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize,
long maxSize,
java.lang.String tempDir)
|
|
| Method Summary | |
protected java.io.File |
createLocalFile()
Creates a file on disk from the current mulitpart element |
static boolean |
equals(byte[] comp,
int offset,
int length,
byte[] source)
Checks bytes for equality. |
int |
getBufferSize()
Get the maximum amount of bytes read from a line at one time |
long |
getMaxSize()
Get the maximum post data size allowed for a multipart request |
MultipartElement |
getNextElement()
Retrieves the next element in the iterator if one exists. |
static java.lang.String |
parseBoundary(java.lang.String contentType)
Parses a content-type String for the boundary. |
static java.lang.String |
parseContentType(java.lang.String contentTypeString)
Parses the "Content-Type" line of a multipart form for a content type |
static java.lang.String |
parseDispositionFilename(java.lang.String dispositionString)
Retrieves the "filename" attribute from a content disposition line |
static java.lang.String |
parseDispositionName(java.lang.String dispositionString)
Retrieves the "name" attribute from a content disposition line |
static java.lang.String |
parseForAttribute(java.lang.String attribute,
java.lang.String parseString)
Parses a string looking for a attribute-value pair, and returns the value. |
protected void |
parseRequest()
Handles retrieving the boundary and setting the input stream |
protected java.lang.String |
readLine()
Reads the input stream until it reaches a new line |
void |
setBufferSize(int bufferSize)
Set the maximum amount of bytes read from a line at one time |
void |
setMaxSize(long maxSize)
Set the maximum post data size allowed for a multipart request |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static int MAX_LINE_SIZE
protected javax.servlet.http.HttpServletRequest request
protected BufferedMultipartInputStream inputStream
protected java.lang.String boundary
protected byte[] boundaryBytes
protected boolean contentRead
protected long maxSize
protected long totalLength
protected int contentLength
protected int diskBufferSize
protected int bufferSize
protected java.lang.String tempDir
| Constructor Detail |
public MultipartIterator(javax.servlet.http.HttpServletRequest request)
throws javax.servlet.ServletException
request - The multipart request to iterate
public MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize)
throws javax.servlet.ServletException
request - The multipart request to iteratebufferSize - The size in bytes that should be read from the input
stream at a times
public MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize,
long maxSize)
throws javax.servlet.ServletException
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
public MultipartIterator(javax.servlet.http.HttpServletRequest request,
int bufferSize,
long maxSize,
java.lang.String tempDir)
throws javax.servlet.ServletException
| Method Detail |
public MultipartElement getNextElement()
throws javax.servlet.ServletException,
java.io.UnsupportedEncodingException
MultipartElement
representing the next element in the request dataa - ServletException if the post size exceeds the maximum file size
passed in the 3 argument constructoran - UnsupportedEncodingException if the "ISO-8859-1" encoding isn't foundpublic void setBufferSize(int bufferSize)
ServletInputStream.readLine(byte[], int, int)public int getBufferSize()
ServletInputStream.readLine(byte[], int, int)public void setMaxSize(long maxSize)
maxSize - The maximum post data size in bytes, set to -1
for no limitpublic long getMaxSize()
protected void parseRequest()
throws javax.servlet.ServletException
public static java.lang.String parseBoundary(java.lang.String contentType)
public static java.lang.String parseContentType(java.lang.String contentTypeString)
contentTypeString - A String reprsenting the Content-Type line,
with a trailing "\n"null if one can't be
found.public static java.lang.String parseDispositionName(java.lang.String dispositionString)
dispositionString - The entire "Content-disposition" stringnull if no name could be found, otherwise,
returns the nameparseForAttribute(String, String)public static java.lang.String parseDispositionFilename(java.lang.String dispositionString)
dispositionString - The entire "Content-disposition" stringnull if no filename could be found, otherwise,
returns the filenameparseForAttribute(String, String)
public static java.lang.String parseForAttribute(java.lang.String attribute,
java.lang.String parseString)
String parseString = "Content-Disposition: filename=\"bob\" name=\"jack\"";
MultipartIterator.parseForAttribute(parseString, "name");
That will return "bob".attribute - The name of the attribute you're trying to getparseString - The string to retrieve the value fromnull if none could be found
protected java.lang.String readLine()
throws javax.servlet.ServletException,
java.io.UnsupportedEncodingException
protected java.io.File createLocalFile()
throws java.io.IOException
fileName - the name of the multipart file
public static boolean equals(byte[] comp,
int offset,
int length,
byte[] source)
comp - The byte to compare to sourceoffset - The offset to start at in complength - The length of comp to compare tosource - The reference byte array to test for equality
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||