A Multipart form data parser. Parses an input stream and writes out any files found, making available a hashtable of other url parameters. As of version 1.17 the files can be saved to memory, and optionally written to a database, etc.
Copyright (C)2001 Jason Pell.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-130\
7 USA
Email: jasonpell@hotmail.com
Url: http://www.geocities.com/jasonpell
Inheritance Path. java.lang.Object-> com.itmill.toolkit.terminal.web.MultipartRequest
Parameters
debug
A PrintWriter that can be used for debugging.
strContentTypeText
The "Content-Type" HTTP header value.
intContentLength
The "Content-Length" HTTP header value.
in
The InputStream to read and parse.
intMaxReadBytes
Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
Exceptions
IllegalArgumentException
If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
IOException
If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
MAX_READ_BYTES
Constructor - load into memory constructor
Parameters
debug
A PrintWriter that can be used for debugging.
strContentTypeText
The "Content-Type" HTTP header value.
intContentLength
The "Content-Length" HTTP header value.
in
The InputStream to read and parse.
strSaveDirectory
The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Exceptions
IllegalArgumentException
If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
IOException
If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
MAX_READ_BYTES
Replaced by MultipartRequest(PrintWriter, String, int, InputStream, int) You can specify MultipartRequest.MAX_READ_BYTES for the intMaxReadBytes parameter
Constructor.
Parameters
debug
A PrintWriter that can be used for debugging.
strContentTypeText
The "Content-Type" HTTP header value.
intContentLength
The "Content-Length" HTTP header value.
in
The InputStream to read and parse.
strSaveDirectory
The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
intMaxReadBytes
Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
Exceptions
IllegalArgumentException
If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
IOException
If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
MAX_READ_BYTES
Constructor.
Parameters
strContentTypeText
The "Content-Type" HTTP header value.
intContentLength
The "Content-Length" HTTP header value.
in
The InputStream to read and parse.
strSaveDirectory
The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
Exceptions
IllegalArgumentException
If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
IOException
If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
MAX_READ_BYTES
Constructor.
Parameters
strContentTypeText
The "Content-Type" HTTP header value.
intContentLength
The "Content-Length" HTTP header value.
in
The InputStream to read and parse.
strSaveDirectory
The temporary directory to save the file from where they can then be moved to wherever by the calling process. If you specify null for this parameter, then any files uploaded will be silently ignored.
intMaxReadBytes
Overrides the MAX_BYTES_READ value, to allow arbitrarily long files.
Exceptions
IllegalArgumentException
If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
IOException
If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.
MAX_READ_BYTES
Constructor.
Prevent a denial of service by defining this, will never read more data. If Content-Length is specified to be more than this, will throw an exception. This limits the maximum number of bytes to the value of an int, which is 2 Gigabytes.
Returns the Content-Type of a file.
Parameters
Returns a null file reference if a call to getFileSize(strName) returns zero or files were uploaded to memory.
Returns a File reference to the uploaded file. This reference is to the files uploaded location, and allows you to read/move/delete the file. This method is only of use, if files were uploaded to the file system. Will return null if uploaded to memory, in which case you should use getFileContents(strName) instead.
Parameters
the contents of the file as a InputStream, or null if not file uploaded, or file uploaded to file system directory.
If files were uploaded into memory, this method will retrieve the contents of the file as a InputStream.
Parameters
strName
is the form field name, used to upload the file. This identifies the formfield location in the storage facility.
strFilename
This is the FileSystemName of the file
type
What attribute you want from the File Parameter. The following types are supported: MultipartRequest.FILENAME, MultipartRequest.CONTENT_TYPE, MultipartRequest.SIZE, MultipartRequest.CONTENTS
The getFileSystemName(String strName),getFileSize(String strName),getContentType(String strName), getContents(String strName) methods all use this method passing in a different type argument.
Note: This class has been changed to provide for future functionality where you will be able to access all files uploaded, even if they are uploaded using the same form field name. At this point however, only the first file uploaded via a form field name is accessible.
Access an attribute of a file upload parameter record.
This enumeration will return all INPUT TYPE=FILE parameter NAMES as encountered during the upload.
Parameters
-1 if file size not defined.
Returns the File Size of a uploaded file.
Parameters
null if strName not found.
Get the file system basename of an uploaded file.
Return the value of the strName URLParameter. If more than one value for a particular Parameter, will return the first. If an error occurs will return null.
Return an enumeration of all values for the strName parameter. Even if a single value for, will always return an enumeration, although it may actually be empty if no value was encountered for strName or it is an invalid parameter name.
This method should be called on the MultipartRequest itself, not on any instances of MultipartRequest, because this sets up the encoding for all instances of multipartrequest. You can set the encoding to null, in which case the default encoding will be applied. The default encoding if this method is not called has been set to ISO-8859-1, which seems to offer the best hope of support for international characters, such as german "Umlaut" characters.
Warning: In multithreaded environments it is the responsibility of the implementer to make sure that this method is not called while another instance is being constructed. When an instance of MultipartRequest is constructed, it parses the input data, and uses the result of getEncoding() to convert between bytes and strings. If setEncoding() is called by another thread, while the private parse() is executing, the method will utilise this new encoding, which may cause serious problems.