| java.lang.Object com.oreilly.servlet.multipart.MultipartParser
MultipartParser | public class MultipartParser (Code) | | A utility class to handle multipart/form-data requests,
the kind of requests that support file uploads. This class uses a
"pull" model where the reading of incoming files and parameters is
controlled by the client code, which allows incoming files to be stored
into any OutputStream . If you wish to use an API which
resembles HttpServletRequest , use the "push" model
MultipartRequest instead. It's an easy-to-use wrapper
around this class.
This class can receive arbitrarily large files (up to an artificial limit
you can set), and fairly efficiently too.
It cannot handle nested data (multipart content within multipart content).
It can now with the latest release handle internationalized content
(such as non Latin-1 filenames).
It also optionally includes enhanced buffering and Content-Length
limitation. Buffering is only required if your servlet container is
poorly implemented (many are, including Tomcat 3.2),
but it is generally recommended because it will make a slow servlet
container a lot faster, and will only make a fast servlet container a
little slower. Content-Length limiting is usually only required if you find
that your servlet is hanging trying to read the input stram from the POST,
and it is similarly recommended because it only has a minimal impact on
performance.
See the included upload.war for an example of how to use this class.
The full file upload specification is contained in experimental RFC 1867,
available at
http://www.ietf.org/rfc/rfc1867.txt.
See Also: com.oreilly.servlet.MultipartRequest author: Jason Hunter author: Geoff Soutter version: 1.11, 2002/11/01, added constructor that takes an encoding, to version: make sure chars are always read correctly version: 1.10, 2002/11/01, added support for a preamble before the first version: boundary marker version: 1.9, 2002/11/01, added support to parse odd Opera Content-Type version: 1.8, 2002/11/01, added support for lynx with unquoted param vals version: 1.7, 2002/04/30, fixed bug if a line was '\n' alone version: 1.6, 2002/04/30, added better internationalization support, thanks version: to Changshin Lee version: 1.5, 2002/04/30, added Opera header fix, thanks to Nic Ferrier version: 1.4, 2001/03/23, added IE5 bug workaround supporting \n as line version: ending, thanks to Michael Alyn Miller version: 1.3, 2001/01/22, added support for boundaries surrounded by quotes version: and content-disposition after content-type, version: thanks to Scott Stark version: 1.2, 2001/01/22, getFilePath() support thanks to Stefan Eissing version: 1.1, 2000/10/29, integrating old WebSphere fix version: 1.0, 2000/10/27, initial revision |
Constructor Summary | |
public | MultipartParser(HttpServletRequest req, int maxSize) Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, buffers for
performance and prevent attempts to read past the amount specified
by the Content-Length. | public | MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, boolean limitLength) Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, and optionally
buffers for performance and prevents attempts to read past the amount
specified by the Content-Length. | public | MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, boolean limitLength, String encoding) Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, and optionally
buffers for performance and prevents attempts to read past the amount
specified by the Content-Length, and with a specified encoding. |
Method Summary | |
public Part | readNextPart() Read the next part arriving in the stream. | public void | setEncoding(String encoding) Sets the encoding used to parse from here onward. |
MultipartParser | public MultipartParser(HttpServletRequest req, int maxSize) throws IOException(Code) | | Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, buffers for
performance and prevent attempts to read past the amount specified
by the Content-Length.
Parameters: req - the servlet request. Parameters: maxSize - the maximum size of the POST content. |
MultipartParser | public MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, boolean limitLength) throws IOException(Code) | | Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, and optionally
buffers for performance and prevents attempts to read past the amount
specified by the Content-Length.
Parameters: req - the servlet request. Parameters: maxSize - the maximum size of the POST content. Parameters: buffer - whether to do internal buffering or let the server buffer,useful for servers that don't buffer Parameters: limitLength - boolean flag to indicate if we need to filter the request's input stream to prevent trying to read past the end of the stream. |
MultipartParser | public MultipartParser(HttpServletRequest req, int maxSize, boolean buffer, boolean limitLength, String encoding) throws IOException(Code) | | Creates a MultipartParser from the specified request,
which limits the upload size to the specified length, and optionally
buffers for performance and prevents attempts to read past the amount
specified by the Content-Length, and with a specified encoding.
Parameters: req - the servlet request. Parameters: maxSize - the maximum size of the POST content. Parameters: buffer - whether to do internal buffering or let the server buffer,useful for servers that don't buffer Parameters: limitLength - boolean flag to indicate if we need to filter the request's input stream to prevent trying to read past the end of the stream. Parameters: encoding - the encoding to use for parsing, default is ISO-8859-1. |
readNextPart | public Part readNextPart() throws IOException(Code) | | Read the next part arriving in the stream. Will be either a
FilePart or a ParamPart , or null
to indicate there are no more parts to read. The order of arrival
corresponds to the order of the form elements in the submitted form.
either a FilePart , a ParamPart ornull if there are no more parts to read. exception: IOException - if an input or output exception has occurred. See Also: FilePart See Also: ParamPart |
setEncoding | public void setEncoding(String encoding)(Code) | | Sets the encoding used to parse from here onward. The default is
ISO-8859-1. Encodings are actually best passed into the contructor,
so even the initial line reads are correct.
Parameters: encoding - The encoding to use for parsing |
|
|