|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.jcorporate.expresso.core.misc.upload.FileItem
This class represents a file that was received by Turbine using
multipart/form-data POST request.
After retrieving an instance of this class from the ParameterParser (see
ParameterParser.getFileItem(String) and ParameterParser.getFileItems(String)) you can use it to acces the
data that was sent by the browser. You may either request all
contents of file at once using get() or request an InputStream with getStream() and
process the file without attempting to load it into memory, which
may come handy with large files.
| Field Summary | |
protected ByteArrayOutputStream |
byteStream
Temporary storage for in-memory files. |
protected byte[] |
content
Cached contents of the file. |
protected String |
contentType
The content type passed by the browser or null if
not defined. |
static int |
DEFAULT_UPLOAD_SIZE_THRESHOLD
The maximal size of request that will have it's elements stored in memory. |
protected String |
fileName
The original filename in the user's filesystem. |
protected File |
storeLocation
Temporary storage location. |
| Constructor Summary | |
protected |
FileItem(String fileName,
String contentType)
Constructs a new FileItem.
|
| Method Summary | |
void |
destroy()
Destroy all content for this form file. |
byte[] |
get()
Returns the contents of the file as an array of bytes. |
String |
getContentType()
Returns the content type passed by the browser or null if not defined. |
byte[] |
getFileData()
Get the data in byte array for for this file. |
String |
getFileName()
Returns the original filename in the user's filesystem. |
int |
getFileSize()
Get the size of this file |
InputStream |
getInputStream()
Get an InputStream that represents this file. |
String |
getName()
Returns the name of the FileItem |
OutputStream |
getOutputStream()
Returns an OutputStream that can
be used for storing the contensts of the file. |
long |
getSize()
Returns the size of the file. |
File |
getStoreLocation()
Returns the File objects for the FileItems's
data temporary location on the disk. |
InputStream |
getStream()
Returns an InputStream that can be
used to retrieve the contents of the file. |
String |
getString()
Returns the contents of the file as a String, using default encoding. |
String |
getString(String encoding)
Returns the contents of the file as a String, using specified encoding. |
boolean |
inMemory()
Provides a hint if the file contents will be read from memory. |
static FileItem |
newInstance(String path,
String name,
String contentType,
int requestSize,
boolean storeAsFile)
Instantiates a FileItem. |
void |
setContentType(String contentType)
Set the content type for this file |
void |
setFileName(String newFileName)
Set the filename of this file |
void |
setFileSize(int filesize)
Set the file size |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_UPLOAD_SIZE_THRESHOLD
protected String fileName
protected String contentType
null if
not defined.
protected byte[] content
protected File storeLocation
protected ByteArrayOutputStream byteStream
| Constructor Detail |
protected FileItem(String fileName,
String contentType)
FileItem.
Use #newInstance(String,String,String,int) to
instantiate FileItems.
fileName - The original filename in the user's filesystem.contentType - The content type passed by the browser or
null if not defined.| Method Detail |
public String getFileName()
getFileName in interface org.apache.struts.upload.FormFilepublic String getContentType()
null if not defined.
getContentType in interface org.apache.struts.upload.FormFilenull if not defined.public boolean inMemory()
True if the file contents will be read
from memory.public long getSize()
public byte[] get()
public String getString()
get() to retrieve the
contents of the file.
public String getString(String encoding)
throws UnsupportedEncodingException
get() to retireve the
contents of the file.
encoding - The encoding to use.
UnsupportedEncodingException
public InputStream getStream()
throws Exception
InputStream that can be
used to retrieve the contents of the file.
InputStream that can be
used to retrieve the contents of the file.
Exception - A generic exception.public File getStoreLocation()
File objects for the FileItems's
data temporary location on the disk. Note that for
FileItems that have their data stored in memory
this method will return null. When handling large
files, you can use File.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.
public OutputStream getOutputStream()
throws IOException
OutputStream that can
be used for storing the contensts of the file.
getOutputStream in interface javax.activation.DataSourceOutputStream that can be
used for storing the contensts of the file.
IOException
public static FileItem newInstance(String path,
String name,
String contentType,
int requestSize,
boolean storeAsFile)
requestSize to
decide what temporary storage approach the new item should
take. The largest request that will have its items cached in
memory can be configured in
TurbineResources.properties in the entry named
file.upload.size.threshold
path - A String.name - The original filename in the user's filesystem.contentType - The content type passed by the browser or
null if not defined.requestSize - The total size of the POST request this item
belongs to.storeAsFile - Set to true if you want it stored as a local file.
public void setContentType(String contentType)
setContentType in interface org.apache.struts.upload.FormFilecontentType - The content typepublic int getFileSize()
getFileSize in interface org.apache.struts.upload.FormFilepublic void setFileSize(int filesize)
setFileSize in interface org.apache.struts.upload.FormFilefilesize - An int reprsenting the size of the file in bytespublic void setFileName(String newFileName)
setFileName in interface org.apache.struts.upload.FormFilenewFileName - The name of the file
public byte[] getFileData()
throws FileNotFoundException,
IOException
getInputStream to get the file
data.
getFileData in interface org.apache.struts.upload.FormFileFileNotFoundException - If some sort of file representation
cannot be found for the FormFile
IOException - If there is some sort of IOException
public InputStream getInputStream()
throws FileNotFoundException,
IOException
getInputStream in interface org.apache.struts.upload.FormFileFileNotFoundException - If some sort of file representation
cannot be found for the FormFile
IOException - If there is some sort of IOExceptionpublic void destroy()
destroy in interface org.apache.struts.upload.FormFilepublic String getName()
getName in interface javax.activation.DataSource
|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||