|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.millstone.webadapter.MultipartRequest
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
Field Summary | |
static int |
CONTENT_TYPE
Type constant for the File CONTENT_TYPE. |
static int |
CONTENTS
Type constant for the File CONTENTS. |
static int |
FILENAME
Type constant for File FILENAME. |
static int |
MAX_READ_BYTES
Prevent a denial of service by defining this, will never read more data. |
static int |
READ_LINE_BLOCK
Defines the number of bytes to read per readLine call. 128K |
static int |
SIZE
Type constant for the File SIZE. |
Constructor Summary | |
MultipartRequest(java.io.PrintWriter debug,
java.lang.String strContentTypeText,
int intContentLength,
java.io.InputStream in,
int intMaxReadBytes)
Constructor - load into memory constructor |
|
MultipartRequest(java.io.PrintWriter debug,
java.lang.String strContentTypeText,
int intContentLength,
java.io.InputStream in,
java.lang.String strSaveDirectory)
Deprecated. Replaced by MultipartRequest(PrintWriter, String, int, InputStream, int) You can specify MultipartRequest.MAX_READ_BYTES for the intMaxReadBytes parameter |
|
MultipartRequest(java.io.PrintWriter debug,
java.lang.String strContentTypeText,
int intContentLength,
java.io.InputStream in,
java.lang.String strSaveDirectory,
int intMaxReadBytes)
Constructor. |
|
MultipartRequest(java.lang.String strContentTypeText,
int intContentLength,
java.io.InputStream in,
java.lang.String strSaveDirectory)
Constructor. |
|
MultipartRequest(java.lang.String strContentTypeText,
int intContentLength,
java.io.InputStream in,
java.lang.String strSaveDirectory,
int intMaxReadBytes)
Constructor. |
Method Summary | |
protected void |
debug(java.lang.String x)
Use when debugging this object. |
java.lang.String |
getContentType(java.lang.String strName)
Returns the Content-Type of a file. |
java.lang.String |
getEncoding()
Returns the current encoding method. |
java.io.File |
getFile(java.lang.String strName)
Returns a File reference to the uploaded file. |
java.io.InputStream |
getFileContents(java.lang.String strName)
If files were uploaded into memory, this method will retrieve the contents of the file as a InputStream. |
java.lang.Object |
getFileParameter(java.lang.String strName,
int type)
Access an attribute of a file upload parameter record. |
java.util.Enumeration |
getFileParameterNames()
This enumeration will return all INPUT TYPE=FILE parameter NAMES as encountered during the upload. |
long |
getFileSize(java.lang.String strName)
Returns the File Size of a uploaded file. |
java.lang.String |
getFileSystemName(java.lang.String strName)
Get the file system basename of an uploaded file. |
java.lang.String |
getHtmlTable()
For debugging. |
java.util.Enumeration |
getParameterNames()
An enumeration of all URL Parameters for the current HTTP Request. |
java.lang.String |
getURLParameter(java.lang.String strName)
Return the value of the strName URLParameter. |
java.util.Enumeration |
getURLParameters(java.lang.String strName)
Return an enumeration of all values for the strName parameter. |
void |
setEncoding(java.lang.String enc)
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MAX_READ_BYTES
public static final int READ_LINE_BLOCK
public static final int FILENAME
public static final int CONTENT_TYPE
public static final int SIZE
public static final int CONTENTS
Constructor Detail |
public MultipartRequest(java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory) throws java.lang.IllegalArgumentException, java.io.IOException
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.
java.lang.IllegalArgumentException
- If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException
- If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.MAX_READ_BYTES
public MultipartRequest(java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes) throws java.lang.IllegalArgumentException, java.io.IOException
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.
java.lang.IllegalArgumentException
- If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException
- If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.MAX_READ_BYTES
public MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory) throws java.lang.IllegalArgumentException, java.io.IOException
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.
java.lang.IllegalArgumentException
- If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException
- If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.MAX_READ_BYTES
public MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, int intMaxReadBytes) throws java.lang.IllegalArgumentException, java.io.IOException
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.
java.lang.IllegalArgumentException
- If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException
- If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.MAX_READ_BYTES
public MultipartRequest(java.io.PrintWriter debug, java.lang.String strContentTypeText, int intContentLength, java.io.InputStream in, java.lang.String strSaveDirectory, int intMaxReadBytes) throws java.lang.IllegalArgumentException, java.io.IOException
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.
java.lang.IllegalArgumentException
- If the strContentTypeText does not contain a Content-Type of "multipart/form-data" or the boundary is not found.
java.io.IOException
- If the intContentLength is higher than MAX_READ_BYTES or strSaveDirectory is invalid or cannot be written to.MAX_READ_BYTES
Method Detail |
public void setEncoding(java.lang.String enc) throws java.io.UnsupportedEncodingException
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.
java.io.UnsupportedEncodingException
public java.lang.String getEncoding()
public java.lang.String getURLParameter(java.lang.String strName)
public java.util.Enumeration getURLParameters(java.lang.String strName)
public java.util.Enumeration getParameterNames()
public java.util.Enumeration getFileParameterNames()
public java.lang.String getContentType(java.lang.String strName)
getFileParameter(java.lang.String, int)
public java.io.InputStream getFileContents(java.lang.String strName)
getFileParameter(java.lang.String, int)
public java.io.File getFile(java.lang.String strName)
getFileSize(java.lang.String)
,
getFileContents(java.lang.String)
,
getFileSystemName(java.lang.String)
public java.lang.String getFileSystemName(java.lang.String strName)
getFileParameter(java.lang.String, int)
public long getFileSize(java.lang.String strName)
getFileParameter(java.lang.String, int)
public java.lang.Object getFileParameter(java.lang.String strName, int type)
strName
- is the form field name, used to upload the file. This identifies
the formfield location in the storage facility.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.
getContentType(java.lang.String)
,
getFileSize(java.lang.String)
,
getFileContents(java.lang.String)
,
getFileSystemName(java.lang.String)
protected void debug(java.lang.String x)
public java.lang.String getHtmlTable()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |