The default implementation of the
FileItem interface.
After retrieving an instance of this class from a FileUpload instance (see
parseRequest(org.), 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.
Temporary files, which are created for file items, will be deleted when the associated request is recycled.
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | cachedContent
Cached contents of the file. |
| private final String | contentType
The content type passed by the browser, or |
| private static final AtomicInteger | COUNTER
Counter used in unique identifier generation. |
| public static final String | DEFAULT_CHARSET
Default content charset to be used when no explicit charset parameter is provided by the sender. |
| private String | defaultCharset
Default content charset to be used when no explicit charset parameter is provided by the sender. |
| private transient DeferredFileOutputStream | dfos
Output stream for this item. |
| private String | fieldName
The name of the form field as provided by the browser. |
| private final String | fileName
The original file name in the user's file system. |
| private FileItemHeaders | headers
The file items headers. |
| private boolean | isFormField
Whether or not this item is a simple form field. |
| private final File | repository
The directory in which uploaded files will be stored, if stored on disk. |
| private long | size
The size of the item, in bytes. |
| private final int | sizeThreshold
The threshold above which uploads will be stored on disk. |
| private transient File | tempFile
The temporary file to use. |
| private static final String | UID
UID used in unique file name generation. |
| Access | Constructor and Description |
|---|---|
| public | DiskFileItem(final String
The name of the form field. fieldName, final String The content type passed by the browser or
contentType, final boolean null if not specified.Whether or not this item is a plain form field, as
opposed to a file upload. isFormField, final String The original file name in the user's file system, or
fileName, final int null if not specified.The threshold, in bytes, below which items will be
retained in memory and above which they will be
stored as a file. sizeThreshold, final File The data repository, which is the directory in
which files will be created, should the item size
exceed the threshold. repository)Constructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | delete()
Implements org. Deletes the underlying storage for a file item, including deleting any associated temporary disk file. |
| public byte[] | Returns: The contents of the file as an array of bytes ornull if the data cannot be readImplements org. Returns the contents of the file as an array of bytes. |
| public String | Returns: The content charset passed by the agent ornull if
not defined.Returns the content charset passed by the agent or |
| public String | Returns: The content type passed by the agent ornull if
not defined.Implements org. Returns the content type passed by the agent or |
| public String | Returns: the default charsetReturns the default charset for use when no explicit charset parameter is provided by the sender. |
| public String | Returns: The name of the form field.Implements org. Returns the name of the field in the multipart form corresponding to this file item. |
| public FileItemHeaders | Returns: The file items headers.Implements org. Returns the file item headers. |
| public InputStream | Returns: AnInputStream that can be
used to retrieve the contents of the file.Implements org. Returns an |
| public String | Returns: The original file name in the client's file system.Implements org. Returns the original file name in the client's file system. |
| public OutputStream | Returns: AnOutputStream that can be used
for storing the contents of the file.Implements org. Returns an |
| public long | Returns: The size of the file, in bytes.Implements org. Returns the size of the file. |
| public File | Returns: The data file, ornull if the data is stored in
memory.Returns the |
| public String | Returns: The contents of the file, as a string.The charset to use. charset)Implements org. Returns the contents of the file as a String, using the specified encoding. |
| public String | Returns: The contents of the file, as a string.Implements org. Returns the contents of the file as a String, using the default character encoding. |
| protected File | Returns: TheFile to be used for temporary storage.Creates and returns a |
| private static String | Returns: A String with the non-random looking instance identifier.Returns an identifier that is unique within the class loader used to load this class, but does not have random-like appearance. |
| public boolean | Returns: true if the instance represents a simple form
field; false if it represents an uploaded file.Implements org. Determines whether or not a |
| public boolean | Returns: true if the file contents will be read
from memory; false otherwise.Implements org. Provides a hint as to whether or not the file contents will be read from memory. |
| public void | setDefaultCharset(final String
the default charset charset)Sets the default charset for use when no explicit charset parameter is provided by the sender. |
| public void | setFieldName(final String
The name of the form field. fieldName)Implements org. Sets the field name used to reference this file item. |
| public void | setFormField(final boolean
true if the instance represents a simple form
field; false if it represents an uploaded file.Implements org. Specifies whether or not a |
| public void | setHeaders(final FileItemHeaders
The file items headers. pHeaders)Implements org. Sets the file item headers. |
| public String | Returns: a string representation of this object.Overrides java. Returns a string representation of this object. |
| public void | write(final File
The file)File into which the uploaded item should
be stored.Implements org. A convenience method to write an uploaded item to disk. |
| cachedContent | back to summary |
|---|---|
| private byte[] cachedContent Cached contents of the file. | |
| contentType | back to summary |
|---|---|
| private final String contentType The content type passed by the browser, or | |
| COUNTER | back to summary |
|---|---|
| private static final AtomicInteger COUNTER Counter used in unique identifier generation. | |
| DEFAULT_CHARSET | back to summary |
|---|---|
| public static final String DEFAULT_CHARSET Default content charset to be used when no explicit charset parameter is provided by the sender. Media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP. | |
| defaultCharset | back to summary |
|---|---|
| private String defaultCharset Default content charset to be used when no explicit charset parameter is provided by the sender. | |
| dfos | back to summary |
|---|---|
| private transient DeferredFileOutputStream dfos Output stream for this item. | |
| fieldName | back to summary |
|---|---|
| private String fieldName The name of the form field as provided by the browser. | |
| fileName | back to summary |
|---|---|
| private final String fileName The original file name in the user's file system. | |
| headers | back to summary |
|---|---|
| private FileItemHeaders headers The file items headers. | |
| isFormField | back to summary |
|---|---|
| private boolean isFormField Whether or not this item is a simple form field. | |
| repository | back to summary |
|---|---|
| private final File repository The directory in which uploaded files will be stored, if stored on disk. | |
| size | back to summary |
|---|---|
| private long size The size of the item, in bytes. This is used to cache the size when a file item is moved from its original location. | |
| sizeThreshold | back to summary |
|---|---|
| private final int sizeThreshold The threshold above which uploads will be stored on disk. | |
| tempFile | back to summary |
|---|---|
| private transient File tempFile The temporary file to use. | |
| UID | back to summary |
|---|---|
| private static final String UID UID used in unique file name generation. | |
| DiskFileItem | back to summary |
|---|---|
| public DiskFileItem(final String fieldName, final String contentType, final boolean isFormField, final String fileName, final int sizeThreshold, final File repository) Constructs a new
| |
| delete | back to summary |
|---|---|
| public void delete() Implements org. Deletes the underlying storage for a file item, including deleting any associated temporary disk file. This method can be used to ensure that this is done at an earlier time, thus preserving system resources.
| |
| get | back to summary |
|---|---|
| public byte[] get() throws UncheckedIOException Implements org. 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.
| |
| getCharSet | back to summary |
|---|---|
| public String getCharSet() Returns the content charset passed by the agent or
| |
| getContentType | back to summary |
|---|---|
| public String getContentType() Implements org. Returns the content type passed by the agent or | |
| getDefaultCharset | back to summary |
|---|---|
| public String getDefaultCharset() Returns the default charset for use when no explicit charset parameter is provided by the sender.
| |
| getFieldName | back to summary |
|---|---|
| public String getFieldName() Implements org. Returns the name of the field in the multipart form corresponding to this file item.
| |
| getHeaders | back to summary |
|---|---|
| public FileItemHeaders getHeaders() Implements org. Returns the file item headers.
| |
| getInputStream | back to summary |
|---|---|
| public InputStream getInputStream() throws IOException Implements org. Returns an
| |
| getName | back to summary |
|---|---|
| public String getName() Implements org. Returns the original file name in the client's file system.
| |
| getOutputStream | back to summary |
|---|---|
| public OutputStream getOutputStream() Implements org. Returns an
| |
| getSize | back to summary |
|---|---|
| public long getSize() Implements org. Returns the size of the file.
| |
| getStoreLocation | back to summary |
|---|---|
| public File getStoreLocation() Returns the
| |
| getString | back to summary |
|---|---|
| public String getString(final String charset) throws UnsupportedEncodingException, IOException Implements org. Returns the contents of the file as a String, using the specified
encoding. This method uses
| |
| getString | back to summary |
|---|---|
| public String getString() Implements org. Returns the contents of the file as a String, using the default
character encoding. This method uses Todo Consider making this method throw UnsupportedEncodingException. | |
| getTempFile | back to summary |
|---|---|
| protected File getTempFile() Creates and returns a Note Subclasses that override this method must ensure that they return the same File each time. | |
| getUniqueId | back to summary |
|---|---|
| private static String getUniqueId() Returns an identifier that is unique within the class loader used to load this class, but does not have random-like appearance.
| |
| isFormField | back to summary |
|---|---|
| public boolean isFormField() Implements org. Determines whether or not a
| |
| isInMemory | back to summary |
|---|---|
| public boolean isInMemory() Implements org. Provides a hint as to whether or not the file contents will be read from memory.
| |
| setDefaultCharset | back to summary |
|---|---|
| public void setDefaultCharset(final String charset) Sets the default charset for use when no explicit charset parameter is provided by the sender.
| |
| setFieldName | back to summary |
|---|---|
| public void setFieldName(final String fieldName) Implements org. Sets the field name used to reference this file item.
| |
| setFormField | back to summary |
|---|---|
| public void setFormField(final boolean state) Implements org. Specifies whether or not a
| |
| setHeaders | back to summary |
|---|---|
| public void setHeaders(final FileItemHeaders pHeaders) Implements org. Sets the file item headers.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this object. | |
| write | back to summary |
|---|---|
| public void write(final File file) throws Exception Implements org. 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. | |