After retrieving an instance of this class from a DiskFileUpload instance (see #parseRequest(javax.servlet.http.HttpServletRequest)), you may either request all contents of file at once using get() or request an InputStream with getInputStream() and process the file without attempting to load it into memory, which may come handy with large files.
Definition at line 100 of file DefaultFileItem.java.
Public Member Functions | |
InputStream | getInputStream () throws IOException |
Returns an InputStream that can be used to retrieve the contents of the file. | |
String | getContentType () |
Returns the content type passed by the browser or null if not defined. | |
String | getName () |
Returns the original filename in the client's filesystem. | |
boolean | isInMemory () |
Provides a hint as to whether or not the file contents will be read from memory. | |
long | getSize () |
Returns the size of the file. | |
byte[] | get () |
Returns the contents of the file as an array of bytes. | |
String | getString (String encoding) throws UnsupportedEncodingException |
Returns the contents of the file as a String, using the specified encoding. | |
String | getString () |
Returns the contents of the file as a String, using the default character encoding. | |
void | write (File file) throws Exception |
A convenience method to write an uploaded item to disk. | |
void | delete () |
Deletes the underlying storage for a file item, including deleting any associated temporary disk file. | |
String | getFieldName () |
Returns the name of the field in the multipart form corresponding to this file item. | |
void | setFieldName (String fieldName) |
Sets the field name used to reference this file item. | |
boolean | isFormField () |
Determines whether or not a FileItem instance represents a simple form field. | |
void | setFormField (boolean state) |
Specifies whether or not a FileItem instance represents a simple form field. | |
OutputStream | getOutputStream () throws IOException |
Returns an OutputStream that can be used for storing the contents of the file. | |
File | getStoreLocation () |
Returns the java.io.File object for the FileItem 's data's temporary location on the disk. | |
Protected Member Functions | |
void | finalize () |
Removes the file contents from the temporary storage. | |
File | getTempFile () |
Creates and returns a File representing a uniquely named temporary file in the configured repository path. | |
Package Functions | |
DefaultFileItem (String fieldName, String contentType, boolean isFormField, String fileName, int sizeThreshold, File repository) | |
Constructs a new DefaultFileItem instance. |
org.apache.commons.fileupload.DefaultFileItem.DefaultFileItem | ( | String | fieldName, | |
String | contentType, | |||
boolean | isFormField, | |||
String | fileName, | |||
int | sizeThreshold, | |||
File | repository | |||
) | [package] |
Constructs a new DefaultFileItem
instance.
fieldName | The name of the form field. | |
contentType | The content type passed by the browser or null if not specified. | |
isFormField | Whether or not this item is a plain form field, as opposed to a file upload. | |
fileName | The original filename in the user's filesystem, or null if not specified. | |
sizeThreshold | The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file. | |
repository | The data repository, which is the directory in which files will be created, should the item size exceed the threshold. |
Definition at line 182 of file DefaultFileItem.java.
InputStream org.apache.commons.fileupload.DefaultFileItem.getInputStream | ( | ) | throws IOException |
Returns an InputStream that can be used to retrieve the contents of the file.
IOException | if an error occurs. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 206 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DeferredFileOutputStream.getData(), org.apache.commons.fileupload.DeferredFileOutputStream.getFile(), and org.apache.commons.fileupload.DeferredFileOutputStream.isInMemory().
String org.apache.commons.fileupload.DefaultFileItem.getContentType | ( | ) |
Returns the content type passed by the browser or null
if not defined.
null
if not defined. Implements org.apache.commons.fileupload.FileItem.
Definition at line 229 of file DefaultFileItem.java.
String org.apache.commons.fileupload.DefaultFileItem.getName | ( | ) |
Returns the original filename in the client's filesystem.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 240 of file DefaultFileItem.java.
boolean org.apache.commons.fileupload.DefaultFileItem.isInMemory | ( | ) |
Provides a hint as to whether or not the file contents will be read from memory.
true
if the file contents will be read from memory; false
otherwise. Implements org.apache.commons.fileupload.FileItem.
Definition at line 256 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DeferredFileOutputStream.isInMemory().
Referenced by org.apache.commons.fileupload.DefaultFileItem.write().
long org.apache.commons.fileupload.DefaultFileItem.getSize | ( | ) |
Returns the size of the file.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 267 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DeferredFileOutputStream.getData(), org.apache.commons.fileupload.DeferredFileOutputStream.getFile(), and org.apache.commons.fileupload.DeferredFileOutputStream.isInMemory().
Referenced by org.apache.commons.fileupload.DefaultFileItem.get().
byte [] org.apache.commons.fileupload.DefaultFileItem.get | ( | ) |
Returns the contents of the file as an array of bytes.
If the contents of the file were not yet cached in memory, they will be loaded from the disk storage and cached.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 291 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DeferredFileOutputStream.getData(), org.apache.commons.fileupload.DeferredFileOutputStream.getFile(), org.apache.commons.fileupload.DefaultFileItem.getSize(), and org.apache.commons.fileupload.DeferredFileOutputStream.isInMemory().
String org.apache.commons.fileupload.DefaultFileItem.getString | ( | String | encoding | ) | throws UnsupportedEncodingException |
Returns the contents of the file as a String, using the specified encoding.
This method uses get() to retrieve the contents of the file.
encoding | The character encoding to use. |
UnsupportedEncodingException | if the requested character encoding is not available. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 345 of file DefaultFileItem.java.
String org.apache.commons.fileupload.DefaultFileItem.getString | ( | ) |
Returns the contents of the file as a String, using the default character encoding.
This method uses get() to retrieve the contents of the file.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 359 of file DefaultFileItem.java.
void org.apache.commons.fileupload.DefaultFileItem.write | ( | File | file | ) | throws Exception |
A convenience method to write an uploaded item to disk.
The client code is not concerned with whether or not the item is stored in memory, or on disk in a temporary location. They just want to write the uploaded item to a file.
This implementation first attempts to rename the uploaded item to the specified destination file, if the item was originally written to disk. Otherwise, the data will be copied to the specified file.
This method is only guaranteed to work once, the first time it is invoked for a particular item. This is because, in the event that the method renames a temporary file, that file will no longer be available to copy or rename again at a later time.
file | The File into which the uploaded item should be stored. |
Exception | if an error occurs. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 385 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DefaultFileItem.getStoreLocation(), and org.apache.commons.fileupload.DefaultFileItem.isInMemory().
void org.apache.commons.fileupload.DefaultFileItem.delete | ( | ) |
Deletes the underlying storage for a file item, including deleting any associated temporary disk file.
Although this storage will be deleted automatically when the FileItem
instance is garbage collected, this method can be used to ensure that this is done at an earlier time, thus preserving system resources.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 471 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DefaultFileItem.getStoreLocation().
String org.apache.commons.fileupload.DefaultFileItem.getFieldName | ( | ) |
Returns the name of the field in the multipart form corresponding to this file item.
Implements org.apache.commons.fileupload.FileItem.
Definition at line 491 of file DefaultFileItem.java.
void org.apache.commons.fileupload.DefaultFileItem.setFieldName | ( | String | fieldName | ) |
Sets the field name used to reference this file item.
fieldName | The name of the form field. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 505 of file DefaultFileItem.java.
boolean org.apache.commons.fileupload.DefaultFileItem.isFormField | ( | ) |
Determines whether or not a FileItem
instance represents a simple form field.
true
if the instance represents a simple form field; false
if it represents an uploaded file.Implements org.apache.commons.fileupload.FileItem.
Definition at line 521 of file DefaultFileItem.java.
Referenced by org.apache.commons.fileupload.DefaultFileItem.setFormField().
void org.apache.commons.fileupload.DefaultFileItem.setFormField | ( | boolean | state | ) |
Specifies whether or not a FileItem
instance represents a simple form field.
state | true if the instance represents a simple form field; false if it represents an uploaded file. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 537 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DefaultFileItem.isFormField().
OutputStream org.apache.commons.fileupload.DefaultFileItem.getOutputStream | ( | ) | throws IOException |
Returns an OutputStream that can be used for storing the contents of the file.
IOException | if an error occurs. |
Implements org.apache.commons.fileupload.FileItem.
Definition at line 552 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DefaultFileItem.getTempFile().
File org.apache.commons.fileupload.DefaultFileItem.getStoreLocation | ( | ) |
Returns the java.io.File object for the FileItem
's data's temporary location on the disk.
Note that for FileItem
s that have their data stored in memory, this method will return null
. When handling large files, you can use java.io.File#renameTo(java.io.File) to move the file to new location without copying the data, if the source and destination locations reside within the same logical volume.
null
if the data is stored in memory. Definition at line 580 of file DefaultFileItem.java.
References org.apache.commons.fileupload.DeferredFileOutputStream.getFile().
Referenced by org.apache.commons.fileupload.DefaultFileItem.delete(), and org.apache.commons.fileupload.DefaultFileItem.write().
File org.apache.commons.fileupload.DefaultFileItem.getTempFile | ( | ) | [protected] |
Creates and returns a File representing a uniquely named temporary file in the configured repository path.
Definition at line 609 of file DefaultFileItem.java.
Referenced by org.apache.commons.fileupload.DefaultFileItem.getOutputStream().