| java.lang.Object org.millstone.webadapter.MultipartRequest
All known Subclasses: org.millstone.webadapter.ServletMultipartRequest,
MultipartRequest | public class MultipartRequest (Code) | | 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-1307 USA
Email: jasonpell@hotmail.com
Url: http://www.geocities.com/jasonpell
author: Jason Pell version: 1.18 Fixed some serious bugs. A new method readAndWrite(InputStream in, OutputStream out) which now does version: the generic processing in common for readAndWriteFile and readFile. The differences are that now version: the two extra bytes at the end of a file upload are processed once, instead of after each line. Also version: if an empty file is encountered, an outputstream is opened, but then deleted if no data written to it. version: The getCharArray() method has been removed. Replaced by the new String(bytes, encoding) method using version: a specific encoding (Defaults to ISO-8859-1) to ensure that extended characters are supported. version: All strings are processed using this encoding. The addition of static methods setEncoding(String) version: and getEncoding() to allow the use of MultipartRequest with a specific encoding type. All instances version: of MultipartRequest will utilise the static charEncoding variable value, that the setEncoding() method version: can be used to set. Started to introduce support for multiple file uploads with the same form field version: name, but not completed for v1.18. 26/06/2001 version: 1.17 A few _very_ minor fixes. Plus a cool new feature added. The ability to save files into memory. version: Thanks to Mark Latham for the idea and some of the code. 11/04/2001 version: 1.16 Added support for multiple parameter values. Also fixed getCharArray(...) method to support version: parameters with non-english ascii values (ascii above 127). Thanks to Stefan Schmidt & version: Michael Elvers for this. (No fix yet for reported problems with Tomcat 3.2 or a single extra version: byte appended to uploads of certain files). By 1.17 hopefully will have a resolution for the version: second problem. 14/03/2001 version: 1.15 A new parameter added, intMaxReadBytes, to allow arbitrary length files. Released under version: the LGPL (Lesser General Public License). 03/02/2001 version: 1.14 Fix for IE problem with filename being empty. This is because IE includes a default Content-Type version: even when no file is uploaded. 16/02/2001 version: 1.13 If an upload directory is not specified, then all file contents are sent into oblivion, but the version: rest of the parsing works as normal. version: 1.12 Fix, was allowing zero length files. Will not even create the output file until there is version: something to write. getFile(String) now returns null, if a zero length file was specified. 06/11/2000 version: 1.11 Fix, in case Content-type is not specified. version: 1.1 Removed dependence on Servlets. Now passes in a generic InputStream instead. version: "Borrowed" readLine from Tomcat 3.1 ServletInputStream class, version: so we can remove some of the dependencies on ServletInputStream. version: Fixed bug where a empty INPUT TYPE="FILE" value, would cause an exception. version: 1.0 Initial Release. |
Field Summary | |
final public static int | CONTENTS Type constant for the File CONTENTS. | final public static int | CONTENT_TYPE Type constant for the File CONTENT_TYPE. | final public static int | FILENAME Type constant for File FILENAME. | final public static int | MAX_READ_BYTES Prevent a denial of service by defining this, will never read more data. | final public static int | READ_LINE_BLOCK Defines the number of bytes to read per readLine call. | final public static int | SIZE Type constant for the File SIZE. |
Constructor Summary | |
public | MultipartRequest(String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory) Constructor.
Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. | public | MultipartRequest(String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory, int intMaxReadBytes) Constructor.
Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. | public | MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory) Constructor.
Parameters: debug - A PrintWriter that can be used for debugging. Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. | public | MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, int intMaxReadBytes) | public | MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory, int intMaxReadBytes) Constructor.
Parameters: debug - A PrintWriter that can be used for debugging. Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. |
CONTENTS | final public static int CONTENTS(Code) | | Type constant for the File CONTENTS.
Note: Only used for file upload to memory.
|
CONTENT_TYPE | final public static int CONTENT_TYPE(Code) | | Type constant for the File CONTENT_TYPE.
|
FILENAME | final public static int FILENAME(Code) | | Type constant for File FILENAME.
|
MAX_READ_BYTES | final public static int MAX_READ_BYTES(Code) | | 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.
|
READ_LINE_BLOCK | final public static int READ_LINE_BLOCK(Code) | | Defines the number of bytes to read per readLine call. 128K
|
SIZE | final public static int SIZE(Code) | | Type constant for the File SIZE.
|
MultipartRequest | public MultipartRequest(String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory) throws IllegalArgumentException, IOException(Code) | | Constructor.
Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. If you specify null for this parameter, then any files uploadedwill be silently ignored. exception: IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found. exception: IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to. See Also: MultipartRequest.MAX_READ_BYTES |
MultipartRequest | public MultipartRequest(String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory, int intMaxReadBytes) throws IllegalArgumentException, IOException(Code) | | Constructor.
Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. If you specify null for this parameter, then any files uploadedwill be silently ignored. Parameters: intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files. exception: IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found. exception: IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to. See Also: MultipartRequest.MAX_READ_BYTES |
MultipartRequest | public MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory) throws IllegalArgumentException, IOException(Code) | | Constructor.
Parameters: debug - A PrintWriter that can be used for debugging. Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. If you specify null for this parameter, then any files uploadedwill be silently ignored. exception: IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found. exception: IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to. See Also: MultipartRequest.MAX_READ_BYTES |
MultipartRequest | public MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, int intMaxReadBytes) throws IllegalArgumentException, IOException(Code) | | Constructor - load into memory constructor
Parameters: debug - A PrintWriter that can be used for debugging. Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files. exception: IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found. exception: IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to. See Also: MultipartRequest.MAX_READ_BYTES |
MultipartRequest | public MultipartRequest(PrintWriter debug, String strContentTypeText, int intContentLength, InputStream in, String strSaveDirectory, int intMaxReadBytes) throws IllegalArgumentException, IOException(Code) | | Constructor.
Parameters: debug - A PrintWriter that can be used for debugging. Parameters: strContentTypeText - The "Content-Type" HTTP header value. Parameters: intContentLength - The "Content-Length" HTTP header value. Parameters: in - The InputStream to read and parse. Parameters: strSaveDirectory - The temporary directory to save the file from where they can then be moved to wherever by thecalling process. If you specify null for this parameter, then any files uploadedwill be silently ignored. Parameters: intMaxReadBytes - Overrides the MAX_BYTES_READ value, to allow arbitrarily long files. exception: IllegalArgumentException - If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found. exception: IOException - If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to. See Also: MultipartRequest.MAX_READ_BYTES |
debug | protected void debug(String x)(Code) | | Use when debugging this object.
|
getEncoding | public String getEncoding()(Code) | | Returns the current encoding method.
|
getFileParameter | public Object getFileParameter(String strName, int type)(Code) | | Access an attribute of a file upload parameter record.
Parameters: strName - is the form field name, used to upload the file. This identifiesthe formfield location in the storage facility. Parameters: strFilename - This is the FileSystemName of the file Parameters: type - What attribute you want from the File Parameter.The following types are supported:MultipartRequest.FILENAME, MultipartRequest.CONTENT_TYPE, MultipartRequest.SIZE,MultipartRequest.CONTENTSThe 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 youwill be able to access all files uploaded, even if they are uploaded using the sameform field name. At this point however, only the first file uploaded via a formfield name is accessible. See Also: MultipartRequest.getContentType(java.lang.String) See Also: MultipartRequest.getFileSize(java.lang.String) See Also: MultipartRequest.getFileContents(java.lang.String) See Also: MultipartRequest.getFileSystemName(java.lang.String) |
getFileParameterNames | public Enumeration getFileParameterNames()(Code) | | This enumeration will return all INPUT TYPE=FILE parameter NAMES as encountered
during the upload.
|
getHtmlTable | public String getHtmlTable()(Code) | | For debugging.
|
getParameterNames | public Enumeration getParameterNames()(Code) | | An enumeration of all URL Parameters for the current HTTP Request.
|
getURLParameter | public String getURLParameter(String strName)(Code) | | 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.
|
getURLParameters | public Enumeration getURLParameters(String strName)(Code) | | 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.
|
setEncoding | public void setEncoding(String enc) throws UnsupportedEncodingException(Code) | | 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.
|
|
|