| java.lang.Object com.oreilly.servlet.multipart.Part com.oreilly.servlet.multipart.FilePart
FilePart | public class FilePart extends Part (Code) | | A FilePart is an upload part which represents a
INPUT TYPE="file" form parameter. Note that because file
upload data arrives via a single InputStream, each FilePart's contents
must be read before moving onto the next part. Don't try to store a
FilePart object for later processing because by then their content will
have been passed by.
author: Geoff Soutter version: 1.2, 2001/01/22, getFilePath() addition thanks to Stefan Eissing version: 1.1, 2000/11/26, writeTo() bug fix thanks to Mike Shivas version: 1.0, 2000/10/27, initial revision |
Method Summary | |
public String | getContentType() Returns the content type of the file data contained within. | public String | getFileName() Returns the name that the file was stored with on the remote system,
or null if the user didn't enter a file to be uploaded. | public String | getFilePath() Returns the full path and name of the file on the remote system,
or null if the user didn't enter a file to be uploaded. | public InputStream | getInputStream() Returns an input stream which contains the contents of the
file supplied. | public boolean | isFile() Returns true to indicate this part is a file. | public void | setRenamePolicy(FileRenamePolicy policy) Puts in place the specified policy for handling file name collisions. | long | write(OutputStream out) Internal method to write this file part; doesn't check to see
if it has contents first. | public long | writeTo(File fileOrDirectory) Write this file part to a file or directory. | public long | writeTo(OutputStream out) Write this file part to the given output stream. |
FilePart | FilePart(String name, ServletInputStream in, String boundary, String contentType, String fileName, String filePath) throws IOException(Code) | | Construct a file part; this is called by the parser.
Parameters: name - the name of the parameter. Parameters: in - the servlet input stream to read the file from. Parameters: boundary - the MIME boundary that delimits the end of file. Parameters: contentType - the content type of the file provided in the MIME header. Parameters: fileName - the file system name of the file provided in the MIME header. Parameters: filePath - the file system path of the file provided in theMIME header (as specified in disposition info). exception: IOException - if an input or output exception has occurred. |
getContentType | public String getContentType()(Code) | | Returns the content type of the file data contained within.
content type of the file data. |
getFileName | public String getFileName()(Code) | | Returns the name that the file was stored with on the remote system,
or null if the user didn't enter a file to be uploaded.
Note: this is not the same as the name of the form parameter used to
transmit the file; that is available from the getName
method. Further note: if file rename logic is in effect, the file
name can change during the writeTo() method when there's a collision
with another file of the same name in the same directory. If this
matters to you, be sure to pay attention to when you call the method.
name of file uploaded or null . See Also: Part.getName |
getFilePath | public String getFilePath()(Code) | | Returns the full path and name of the file on the remote system,
or null if the user didn't enter a file to be uploaded.
If path information was not supplied by the remote system, this method
will return the same as getFileName() .
path of file uploaded or null . See Also: Part.getName |
getInputStream | public InputStream getInputStream()(Code) | | Returns an input stream which contains the contents of the
file supplied. If the user didn't enter a file to upload
there will be 0 bytes in the input stream.
It's important to read the contents of the InputStream
immediately and in full before proceeding to process the
next part. The contents will otherwise be lost on moving
to the next part.
an input stream containing contents of file. |
isFile | public boolean isFile()(Code) | | Returns true to indicate this part is a file.
true. |
setRenamePolicy | public void setRenamePolicy(FileRenamePolicy policy)(Code) | | Puts in place the specified policy for handling file name collisions.
|
write | long write(OutputStream out) throws IOException(Code) | | Internal method to write this file part; doesn't check to see
if it has contents first.
number of bytes written. exception: IOException - if an input or output exception has occurred. |
writeTo | public long writeTo(File fileOrDirectory) throws IOException(Code) | | Write this file part to a file or directory. If the user
supplied a file, we write it to that file, and if they supplied
a directory, we write it to that directory with the filename
that accompanied it. If this part doesn't contain a file this
method does nothing.
number of bytes written exception: IOException - if an input or output exception has occurred. |
writeTo | public long writeTo(OutputStream out) throws IOException(Code) | | Write this file part to the given output stream. If this part doesn't
contain a file this method does nothing.
number of bytes written. exception: IOException - if an input or output exception has occurred. |
|
|