com.bentofw.mime
Class ParsedData
java.lang.Object
com.bentofw.mime.ParsedData
public class ParsedData
- extends java.lang.Object
Represents the HTTP POST request with multipart/form-data.
Once the multipart/form-data is parsed by MimeParser, you
can access:
- the binary contents of the uploaded file
- the text contents of the uploaded file
- the text contents of the text parameter
In addition to them, this class implements useful methods
to manage the parsed POST request.
- Author:
- Jun Inamori
|
Method Summary |
boolean |
containsFile(java.lang.String name)
Returns true if the file is uploaded by the specified
parameter name. |
SavedFile[] |
getAllFiles()
Returns the array of SavedFile instances. |
byte[] |
getBinaryContents(java.lang.String name)
Returns the binary contents of the uploaded file. |
java.io.File |
getFile(java.lang.String name)
Returns the instance of java.io.File for the file
which is saved into the local file system. |
java.lang.String[] |
getFileKeys()
Returns the array of names for all the FILE INPUT in the
FORM. |
java.io.InputStream |
getInputStream(java.lang.String name)
Returns the InputStream to the binary contents of the
uploaded file. |
java.lang.String |
getMimeType(java.lang.String name)
Returns the mime-type for the uploaded file. |
java.lang.String |
getOriginalFileName(java.lang.String name)
Returns the original file name for the uploaded file. |
java.lang.String |
getParameter(java.lang.String name)
Returns the value of the text parameter in your FORM,
or null if the parameter does not exist. |
java.util.Set |
getParameterNames()
Returns an Set of String objects,
containing the names of the text parameters in your FORM. |
java.lang.String[] |
getParameterValues(java.lang.String name)
Returns an array of String objects, each of which is
the value of the specified text parameter. |
java.lang.String |
getTextContents(java.lang.String name)
Returns the text contents of the uploaded file. |
void |
saveBinaryContents(java.lang.String name,
java.io.File file)
Writes the binary contents of the uploaded file into the
local file. |
void |
saveBinaryContents(java.lang.String name,
java.lang.String file)
Writes the binary contents of the uploaded file into the
local file. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
getParameter
public java.lang.String getParameter(java.lang.String name)
- Returns the value of the text parameter in your FORM,
or null if the parameter does not exist.
The text parameter includes:
- INPUT with the type of TEXT
- INPUT with the type of HIDDEN
- INPUT with the type of PASSWORD
- INPUT with the type of CHECKBOX
- INPUT with the type of RADIO
- INPUT with the type of SUBMIT
- SELECT
- TEXTAREA
Note that the contents of the uploaded files are not
available through this method.
In other words,
- INPUT with the type of FILE
is out of scope of this method.
To get the contents of
the uploaded files, please use:
You should only use this method when you are sure the
parameter has only one value. If the parameter might have
more than one value, use
If you use this method with a multivalued parameter, the
value returned is equal to the first value in the array
returned by getParameterValues(String).
- Parameters:
name - a String specifying the name of the
parameter.
- Returns:
- a String representing the single value of the
parameter.
- See Also:
getParameterValues(String)
getParameterNames
public java.util.Set getParameterNames()
- Returns an Set of String objects,
containing the names of the text parameters in your FORM.
The text parameter includes:
- INPUT with the type of TEXT
- INPUT with the type of HIDDEN
- INPUT with the type of PASSWORD
- INPUT with the type of CHECKBOX
- INPUT with the type of RADIO
- INPUT with the type of SUBMIT
- SELECT
- TEXTAREA
Note that the parameter names of the uploaded files are not
available through this method.
In other words,
- INPUT with the type of FILE
is out of scope of this method.
To get the parameter names of the uploaded files,
please use:
If the request has no parameters, the method returns an
empty Set.
- Returns:
- an Set of String objects, each
String containing the name of a request parameter;
or an empty Set if the request has no
parameters
getParameterValues
public java.lang.String[] getParameterValues(java.lang.String name)
- Returns an array of String objects, each of which is
the value of the specified text parameter.
The text parameter includes:
- INPUT with the type of TEXT
- INPUT with the type of HIDDEN
- INPUT with the type of PASSWORD
- INPUT with the type of CHECKBOX
- INPUT with the type of RADIO
- INPUT with the type of SUBMIT
- SELECT
- TEXTAREA
The name of text parameter must be specified for this method.
If the value for the specified text parameter is not found
in the request, this method returns null.
Note that the contents of the uploaded files are not
available through this method.
In other words,
- INPUT with the type of FILE
is out of scope of this method.
To get the contents of
the uploaded file, please use:
- Parameters:
name - a String containing the name of the
parameter whose value is requested.
- Returns:
- an array of String objects containing the
parameter's values
- See Also:
getParameter(String)
getFileKeys
public java.lang.String[] getFileKeys()
- Returns the array of names for all the FILE INPUT in the
FORM.
For example, when the files are uploaded from the FORM like:
this method returns {"photo","profile"}
- Returns:
- The array of names for all the FILE INPUT in the
FORM.
getBinaryContents
public byte[] getBinaryContents(java.lang.String name)
throws java.io.IOException
- Returns the binary contents of the uploaded file.
The name of FILE INPUT must be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to get the binary contents of the file
uploaded by the first FILE INPUT, the parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The binary contents of the uploaded file.
- Throws:
java.io.IOException- See Also:
getFileKeys(),
getTextContents(String),
getFile(String),
getInputStream
public java.io.InputStream getInputStream(java.lang.String name)
throws java.io.IOException
- Returns the InputStream to the binary contents of the
uploaded file. The name of FILE INPUT must be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to get the binary contents of the file
uploaded by the first FILE INPUT, the parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The InputStream to the binary contents of the
uploaded file.
- Throws:
java.io.IOException- Since:
- 3.2
- See Also:
getFileKeys(),
getTextContents(String),
getFile(String),
saveBinaryContents
public void saveBinaryContents(java.lang.String name,
java.lang.String file)
throws SimpleException,
java.io.IOException
- Writes the binary contents of the uploaded file into the
local file.
The name of FILE INPUT parameter in your FORM must be
specified.
For example, when the files are uploaded from the FORM like:
and you'd like to save the binary contents of the file
uploaded by the first FILE INPUT, the first parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
The path to the local file must be specified by the second
parameter.
This method works only when you use one of
which do not save the uploaded files. If you use
parseAndSave(...) methods which save the uploaded
files, this method throws the exception.
- Parameters:
name - The name of FILE INPUT parameter
in your FORM.file - The path to the local file where the binary
contents will be saved.
- Throws:
SimpleException
java.io.IOException- Since:
- 2.0
- See Also:
saveBinaryContents
public void saveBinaryContents(java.lang.String name,
java.io.File file)
throws SimpleException,
java.io.IOException
- Writes the binary contents of the uploaded file into the
local file.
The name of FILE INPUT parameter in your FORM must be
specified.
For example, when the files are uploaded from the FORM like:
and you'd like to save the binary contents of the file
uploaded by the first FILE INPUT, the first parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
The path to the local file must be specified by the second
parameter.
This method works only when you use one of
which do not save the uploaded files. If you use
parseAndSave(...) methods which save the uploaded
files, this method throws the exception.
- Parameters:
name - The name of FILE INPUT parameter
in your FORM.file - The path to the local file where the binary
contents will be saved.
- Throws:
SimpleException
java.io.IOException- Since:
- 2.0
- See Also:
containsFile
public boolean containsFile(java.lang.String name)
- Returns true if the file is uploaded by the specified
parameter name. Otherwise, returns false.
The name of FILE INPUT parameter in your FORM must be
specified.
For example, when the files are uploaded from the FORM like:
and you'd like to see if the file is uploaded by the first
FILE INPUT or not, the first parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
- Parameters:
name - The name of FILE INPUT parameter
in your FORM.- Since:
- 2.1
getTextContents
public java.lang.String getTextContents(java.lang.String name)
throws java.io.IOException
- Returns the text contents of the uploaded file.
The name of FILE INPUT must be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to get the text contents of the file uploaded
by the second FILE INPUT, the first parameter of
this method is profile. This parameter is required
because the single FORM can upload the multiple files
at the same time.
The file contents are converted into Java String
using the charset which is used
to decode the text parameters.
For details about the charset, please read
another page.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The text contents of the uploaded file.
- Throws:
java.io.IOException- See Also:
getFileKeys(),
getBinaryContents(String),
getFile(String)
getFile
public java.io.File getFile(java.lang.String name)
- Returns the instance of java.io.File for the file
which is saved into the local file system.
The name of FILE INPUT parameter in your FORM must
be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to access the file
uploaded by the first FILE INPUT, the parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
This method works only when you use one of
MimeParser.parseAndSave(HttpServletRequest,String,String,int)
MimeParser.parseAndSave(HttpServletRequest,String,String)
MimeParser.parseAndSave(HttpServletRequest,String,String,int,Set)
MimeParser.parseAndSave(HttpServletRequest,String,String,Set)
which save the uploaded files. If you use
parseOnly(...) methods which do not save the
uploaded files, this method returns null.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The instance of java.io.File for the file
which is saved into the local file system.
- See Also:
getFileKeys(),
getMimeType
public java.lang.String getMimeType(java.lang.String name)
- Returns the mime-type for the uploaded file.
The name of FILE INPUT parameter in your FORM must
be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to know the mime-type of the file
uploaded by the first FILE INPUT, the parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The mime-type for the uploaded file.
- Since:
- 1.2
- See Also:
getFileKeys(),
getAllFiles()
getOriginalFileName
public java.lang.String getOriginalFileName(java.lang.String name)
- Returns the original file name for the uploaded file.
The name of FILE INPUT parameter in your FORM must
be specified.
For example, when the files are uploaded from the FORM like:
and you'd like to know the original name of the file
uploaded by the first FILE INPUT, the parameter of
this method is photo. This parameter is required
because the single FORM can upload the multiple files
at the same time.
- Parameters:
name - The name of FILE INPUT.
- Returns:
- The original file name for the uploaded file.
- Since:
- 1.3
- See Also:
getFileKeys(),
getAllFiles()
getAllFiles
public SavedFile[] getAllFiles()
- Returns the array of
SavedFile instances.
The instance of SavedFile represents:
- the name of FILE INPUT in your FORM
- java.io.File on the server side
This method works only when you use one of
MimeParser.parseAndSave(HttpServletRequest,String,String,int)
MimeParser.parseAndSave(HttpServletRequest,String,String)
MimeParser.parseAndSave(HttpServletRequest,String,String,int,Set)
MimeParser.parseAndSave(HttpServletRequest,String,String,Set)
which save the uploaded files. If you use
parseOnly(...) methods which do not save the
uploaded files, this method returns null.
- Returns:
- The array of SavedFile instances.
- See Also:
SavedFile,
ALL CONTENTS COPYRIGHT 2005, OOP-Research Corporation. All rights reserved.
Any questions and comments are welcome to OOP-Research Corporation.