All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.oreilly.servlet.multipart.MultipartParser

java.lang.Object
   |
   +----com.oreilly.servlet.multipart.MultipartParser

public class MultipartParser
extends Object
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) or 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.

Version:
1.3, 2001/01/22, added support for boundaries surrounded by quotes and content-disposition after content-type, thanks to Scott Stark
Author:
Jason Hunter, Geoff Soutter
See Also:
MultipartRequest

Constructor Index

 o MultipartParser(HttpServletRequest, int)
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.
 o MultipartParser(HttpServletRequest, int, boolean, boolean)
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.

Method Index

 o readNextPart()
Read the next part arriving in the stream.

Constructors

 o MultipartParser
 public MultipartParser(HttpServletRequest req,
                        int maxSize) throws IOException
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.
maxSize - the maximum size of the POST content.
 o MultipartParser
 public MultipartParser(HttpServletRequest req,
                        int maxSize,
                        boolean buffer,
                        boolean limitLength) throws IOException
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.
maxSize - the maximum size of the POST content.
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.

Methods

 o readNextPart
 public Part readNextPart() throws IOException
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.

Returns:
either a FilePart, a ParamPart or null if there are no more parts to read.
Throws: IOException
if an input or output exception has occurred.
See Also:
FilePart, ParamPart

All Packages  Class Hierarchy  This Package  Previous  Next  Index