Package org.apache.struts.upload
Interface FormFile
- All Superinterfaces:
Serializable
This interface represents a file that has been uploaded by a client. It is
the only interface or class in upload package which is typically referenced
directly by a Struts application.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Destroys all content for the uploaded file, including any underlying data files.Returns the content type for this file.byte[]
Returns the data for the entire file as byte array.long
Returns the length of this file.Returns the file name of this file.int
Deprecated.Returns an input stream for this file.void
setContentType
(String contentType) Sets the content type for this file.void
setFileLength
(long fileLength) Sets the file length.void
setFileName
(String fileName) Sets the file name of this file.void
setFileSize
(int size) Deprecated.
-
Method Details
-
getContentType
String getContentType()Returns the content type for this file.- Returns:
- A String representing content type.
-
setContentType
Sets the content type for this file.- Parameters:
contentType
- The content type for the file.
-
getFileSize
Deprecated.usegetFileLength()
Returns the size of this file.- Returns:
- The size of the file, in bytes.
- Throws:
IllegalStateException
- if size is greater than 2GB- See Also:
-
setFileSize
Deprecated.Sets the file size.- Parameters:
size
- The size of the file, in bytes.- See Also:
-
getFileLength
long getFileLength()Returns the length of this file.- Returns:
- The length of the file, in bytes.
-
setFileLength
void setFileLength(long fileLength) Sets the file length.- Parameters:
fileLength
- The length of the file, in bytes.
-
getFileName
String getFileName()Returns the file name of this file. This is the base name of the file, as supplied by the user when the file was uploaded.- Returns:
- The base file name.
-
setFileName
Sets the file name of this file.- Parameters:
fileName
- The base file name.
-
getFileData
Returns the data for the entire file as byte array. Care is needed when using this method, since a large upload could easily exhaust available memory. The preferred method for accessing the file data isgetInputStream
.- Returns:
- The file data as a byte array.
- Throws:
FileNotFoundException
- if the uploaded file is not found. Some implementations may not deal with files and/or throw this exception.IOException
- if an error occurred while reading the file.
-
getInputStream
Returns an input stream for this file. The caller must close the stream when it is no longer needed.- Throws:
FileNotFoundException
- if the uploaded file is not found. Some implementations may not deal with files and/or throw this exception.IOException
- if an error occurred while reading the file.
-
destroy
Destroys all content for the uploaded file, including any underlying data files.- Throws:
IOException
- if an error occurred while destroying all content.
-
getFileLength()