|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.waveset.ui.util.RequestTokenizer
This class serially processes an HTTP request input stream,
parsing one parameter at a time. This class allows the caller
to access the parameter content as a string or as an input stream.
Styled after InputStreamTokenizer
,
which allows the caller to iterate word or number tokens.
Iterating tokens of the HTTP request input stream is a bit less convenient for the caller, but this minimizes the amount of memory required to read request parameters. By comparison, getParameter() and getParameterMap() read the entire request into memory.
Reading parameter content as an input stream enables memory-efficient uploading of large files.
NOTE: this class handles "multipart/mixed" content as described in the HTML 4.01 Specification. Therefore, it will handle a file select control from which multiple files have been selected.
We expect the call pattern to be something like:
HttpServletRequest request = requestState.getRequest();
RequestTokenizer rt = new RequestTokenizer(request);
String parameter = null;
while (rt.nextParameter()!=null) {
String parameterName = rt.getName();
if (PARAMETER_X.equals(parameterName)) {
_parameterX = rt.getContentString();
}
else if (LOAD_FILE.equals(parameterName)) {
String fileName = rt.getFileName();
if (fileName!=null && fileName.length()>0) {
OutputStream os = new FileOutputStream(fileName);
InputStream is = rt.getContentStream();
Util.copyFile(is, os);
}
}
} // end while
Field Summary | |
static java.lang.String |
code_id
|
protected static java.lang.String |
COLON
|
protected static java.lang.String |
CONTENT
|
protected static java.lang.String |
CONTENT_DISPOSITION
|
protected static java.lang.String |
CONTENT_TRANSFER_ENCODING
|
protected static java.lang.String |
CONTENT_TYPE
|
protected static java.lang.String |
CRLF
|
protected static java.lang.String |
DASH_DASH
|
protected static java.lang.String |
EQUALS
|
protected static java.lang.String |
FILENAME
|
protected static java.lang.String |
MULTI_PART_FORM_DATA
|
protected static java.lang.String |
MULTI_PART_MIXED
|
protected static java.lang.String |
NAME
|
protected static java.lang.String |
QUOTE
|
protected static java.lang.String |
SPACE
|
protected static Trace |
trace
|
Constructor Summary | |
RequestTokenizer(javax.servlet.http.HttpServletRequest request)
|
Method Summary | |
java.lang.String |
getContentDisposition()
|
java.io.InputStream |
getContentStream()
|
java.lang.String |
getContentString()
|
java.lang.String |
getContentTransferEncoding()
|
java.lang.String |
getContentType()
|
java.lang.String |
getFileName()
|
java.lang.String |
getName()
|
java.lang.String |
nextParameter()
Advance to the next parameter in the request input stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String code_id
protected static Trace trace
protected static final java.lang.String MULTI_PART_FORM_DATA
protected static final java.lang.String MULTI_PART_MIXED
protected static final java.lang.String COLON
protected static final java.lang.String EQUALS
protected static final java.lang.String SPACE
protected static final java.lang.String QUOTE
protected static final java.lang.String CRLF
protected static final java.lang.String DASH_DASH
protected static final java.lang.String CONTENT
protected static final java.lang.String CONTENT_DISPOSITION
protected static final java.lang.String CONTENT_TRANSFER_ENCODING
protected static final java.lang.String CONTENT_TYPE
protected static final java.lang.String FILENAME
protected static final java.lang.String NAME
Constructor Detail |
public RequestTokenizer(javax.servlet.http.HttpServletRequest request)
Method Detail |
public java.lang.String getContentType()
Before calling nextParameter(), or after nextParameter() returns null, this will return null.
nextParameter()
public java.lang.String getName()
Before calling nextParameter(), or after nextParameter() returns null, this will return null.
nextParameter()
public java.lang.String getContentDisposition()
Before calling nextParameter(), or after nextParameter() returns null, this will return null.
nextParameter()
public java.lang.String getContentTransferEncoding()
If the request parameter does not specify a content transfer encoding (e.g., because it is the default), this method returns null.
Before calling nextParameter(), or after nextParameter() returns null, this method will return null.
nextParameter()
public java.lang.String getFileName()
Before calling nextParameter(), or after nextParameter() returns null, this will return null.
nextParameter()
public java.lang.String getContentString() throws IOException
String
.
java.lang.IllegalStateException
- if this method is called
after calling getContentStream() for the same parameter.
java.lang.UnsupportedOperationException
- if this method is called
on a parameter whose content length exceeds the configured
maximum.
This method will return null if nextParameter() has not been called (to advance to the first request parameter) or if nextParameter() returns null (because we have advanced beyond the last parameter).
IOException
nextParameter()
public java.io.InputStream getContentStream()
InputStream
.
java.lang.IllegalStateException
- if this method is called
after calling getContentString() for the same parameter.
This method will return null if nextParameter() has not been called (to advance to the first request parameter) or if nextParameter() returns null (because we have advanced beyond the last parameter).
nextParameter()
public java.lang.String nextParameter() throws IOException
java.lang.IllegalArgumentException
- if there is an error parsing the request input stream.
IOException
- if there is an error reading the request input stream.
After a call to nextParameter()
,
the caller may retrieve the parameter's:
getName()
.
getContentType()
.
getContentDisposition()
.
getContentTransferEncoding()
.
String
by calling getContentString()
,
or as an InputStream
by calling getContentStream()
.
getFileName()
.
(If the parameter was not a file, the file name will be null.)
getContentString()
,
getContentStream()
,
getContentType()
,
getContentDisposition()
,
getContentTransferEncoding()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |