Package play.data.parsing
Class ApacheMultipartParser.AutoFileItem
java.lang.Object
play.data.parsing.ApacheMultipartParser.AutoFileItem
- All Implemented Interfaces:
org.apache.commons.fileupload.FileItem,org.apache.commons.fileupload.FileItemHeadersSupport
- Enclosing class:
- ApacheMultipartParser
public static class ApacheMultipartParser.AutoFileItem
extends Object
implements org.apache.commons.fileupload.FileItem
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault content charset to be used when no explicit charset parameter is provided by the sender. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete()Deletes the underlying storage for a file item, including deleting any associated temporary disk file.byte[]get()Returns the contents of the file as an array of bytes.Returns the content charset passed by the agent ornullif not defined.Returns the content type passed by the agent ornullif not defined.Returns the name of the field in the multipart form corresponding to this file item.org.apache.commons.fileupload.FileItemHeadersReturns the file item headers.Returns anInputStreamthat can be used to retrieve the contents of the file.getName()Returns the original filename in the client's filesystem.Returns anOutputStreamthat can be used for storing the contents of the file.longgetSize()Returns the size of the file.Returns theFileobject for theFileItem's data's temporary location on the disk.Returns the contents of the file as a String, using the default character encoding.Returns the contents of the file as a String, using the specified encoding.protected FileCreates and returns aFilerepresenting a uniquely named temporary file in the configured repository path.booleanDetermines whether or not aFileIteminstance represents a simple form field.booleanProvides a hint as to whether or not the file contents will be read from memory.voidsetFieldName(String fieldName) Sets the field name used to reference this file item.voidsetFormField(boolean state) Specifies whether or not aFileIteminstance represents a simple form field.voidsetHeaders(org.apache.commons.fileupload.FileItemHeaders pHeaders) Sets the file item headers.toString()voidA convenience method to write an uploaded item to disk.
-
Field Details
-
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.- See Also:
-
-
Constructor Details
-
AutoFileItem
public AutoFileItem(org.apache.commons.fileupload.FileItemStream stream)
-
-
Method Details
-
getInputStream
Returns anInputStreamthat can be used to retrieve the contents of the file.- Specified by:
getInputStreamin interfaceorg.apache.commons.fileupload.FileItem- Returns:
- An
InputStreamthat can be used to retrieve the contents of the file. - Throws:
IOException- if an error occurs.
-
getContentType
Returns the content type passed by the agent ornullif not defined.- Specified by:
getContentTypein interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The content type passed by the agent or
nullif not defined.
-
getCharSet
Returns the content charset passed by the agent ornullif not defined.- Returns:
- The content charset passed by the agent or
nullif not defined.
-
getName
Returns the original filename in the client's filesystem.- Specified by:
getNamein interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The original filename in the client's filesystem.
-
isInMemory
public boolean isInMemory()Provides a hint as to whether or not the file contents will be read from memory.- Specified by:
isInMemoryin interfaceorg.apache.commons.fileupload.FileItem- Returns:
trueif the file contents will be read from memory;falseotherwise.
-
getSize
public long getSize()Returns the size of the file.- Specified by:
getSizein interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The size of the file, in bytes.
-
get
public byte[] 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.- Specified by:
getin interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The contents of the file as an array of bytes.
-
getString
Returns the contents of the file as a String, using the specified encoding. This method usesget()to retrieve the contents of the file.- Specified by:
getStringin interfaceorg.apache.commons.fileupload.FileItem- Parameters:
charset- The charset to use.- Returns:
- The contents of the file, as a string.
- Throws:
UnsupportedEncodingException- if the requested character encoding is not available.
-
getString
Returns the contents of the file as a String, using the default character encoding. This method usesget()to retrieve the contents of the file.- Specified by:
getStringin interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The contents of the file, as a string.
-
write
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.
- Specified by:
writein interfaceorg.apache.commons.fileupload.FileItem- Parameters:
file- TheFileinto which the uploaded item should be stored.- Throws:
IOExceptionorg.apache.commons.fileupload.FileUploadException
-
delete
public void delete()Deletes the underlying storage for a file item, including deleting any associated temporary disk file. Although this storage will be deleted automatically when theFileIteminstance is garbage collected, this method can be used to ensure that this is done at an earlier time, thus preserving system resources.- Specified by:
deletein interfaceorg.apache.commons.fileupload.FileItem
-
getFieldName
Returns the name of the field in the multipart form corresponding to this file item.- Specified by:
getFieldNamein interfaceorg.apache.commons.fileupload.FileItem- Returns:
- The name of the form field.
- See Also:
-
setFieldName
Sets the field name used to reference this file item.- Specified by:
setFieldNamein interfaceorg.apache.commons.fileupload.FileItem- Parameters:
fieldName- The name of the form field.- See Also:
-
isFormField
public boolean isFormField()Determines whether or not aFileIteminstance represents a simple form field.- Specified by:
isFormFieldin interfaceorg.apache.commons.fileupload.FileItem- Returns:
trueif the instance represents a simple form field;falseif it represents an uploaded file.- See Also:
-
setFormField
public void setFormField(boolean state) Specifies whether or not aFileIteminstance represents a simple form field.- Specified by:
setFormFieldin interfaceorg.apache.commons.fileupload.FileItem- Parameters:
state-trueif the instance represents a simple form field;falseif it represents an uploaded file.- See Also:
-
getOutputStream
Returns anOutputStreamthat can be used for storing the contents of the file.- Specified by:
getOutputStreamin interfaceorg.apache.commons.fileupload.FileItem- Returns:
- An
OutputStreamthat can be used for storing the contents of the file.
-
getStoreLocation
Returns theFileobject for theFileItem's data's temporary location on the disk. Note that forFileItems that have their data stored in memory, this method will returnnull. When handling large files, you can useFile.renameTo(File)to move the file to new location without copying the data, if the source and destination locations reside within the same logical volume.- Returns:
- The data file, or
nullif the data is stored in memory.
-
getTempFile
Creates and returns aFilerepresenting a uniquely named temporary file in the configured repository path. The lifetime of the file is tied to the lifetime of theFileIteminstance; the file will be deleted when the instance is garbage collected.- Returns:
- The
Fileto be used for temporary storage.
-
toString
-
getHeaders
public org.apache.commons.fileupload.FileItemHeaders getHeaders()Returns the file item headers.- Specified by:
getHeadersin interfaceorg.apache.commons.fileupload.FileItemHeadersSupport- Returns:
- The file items headers.
-
setHeaders
public void setHeaders(org.apache.commons.fileupload.FileItemHeaders pHeaders) Sets the file item headers.- Specified by:
setHeadersin interfaceorg.apache.commons.fileupload.FileItemHeadersSupport- Parameters:
pHeaders- The file items headers.
-