org.apache.struts.upload

Class CommonsMultipartRequestHandler.CommonsFormFile

static class CommonsMultipartRequestHandler.CommonsFormFile extends Object implements FormFile, Serializable

This class implements the Struts FormFile interface by wrapping the Commons FileUpload FileItem interface. This implementation is read-only; any attempt to modify an instance of this class will result in an UnsupportedOperationException.
Field Summary
FileItemfileItem
The FileItem instance wrapped by this object.
Constructor Summary
CommonsFormFile(FileItem fileItem)
Constructs an instance of this class which wraps the supplied file item.
Method Summary
voiddestroy()
Destroy all content for this form file.
protected StringgetBaseFileName(String filePath)
Returns the base file name from the supplied file path.
StringgetContentType()
Returns the content type for this file.
byte[]getFileData()
Returns the data for this file as a byte array.
StringgetFileName()
Returns the (client-side) file name for this file.
intgetFileSize()
Returns the size, in bytes, of this file.
InputStreamgetInputStream()
Get an InputStream that represents this file.
voidsetContentType(String contentType)
Sets the content type for this file.
voidsetFileName(String fileName)
Sets the (client-side) file name for this file.
voidsetFileSize(int filesize)
Sets the size, in bytes, for this file.
StringtoString()
Returns the (client-side) file name for this file.

Field Detail

fileItem

FileItem fileItem
The FileItem instance wrapped by this object.

Constructor Detail

CommonsFormFile

public CommonsFormFile(FileItem fileItem)
Constructs an instance of this class which wraps the supplied file item.

Parameters: fileItem The Commons file item to be wrapped.

Method Detail

destroy

public void destroy()
Destroy all content for this form file. Implementations should remove any temporary files or any temporary file data stored somewhere

getBaseFileName

protected String getBaseFileName(String filePath)
Returns the base file name from the supplied file path. On the surface, this would appear to be a trivial task. Apparently, however, some Linux JDKs do not implement File.getName() correctly for Windows paths, so we attempt to take care of that here.

Parameters: filePath The full path to the file.

Returns: The base file name, from the end of the path.

getContentType

public String getContentType()
Returns the content type for this file.

Returns: A String representing content type.

getFileData

public byte[] getFileData()
Returns the data for this file as a byte array. Note that this may result in excessive memory usage for large uploads. The use of the getInputStream method is encouraged as an alternative.

Returns: An array of bytes representing the data contained in this form file.

Throws: FileNotFoundException If some sort of file representation cannot be found for the FormFile IOException If there is some sort of IOException

getFileName

public String getFileName()
Returns the (client-side) file name for this file.

Returns: The client-size file name.

getFileSize

public int getFileSize()
Returns the size, in bytes, of this file.

Returns: The size of the file, in bytes.

getInputStream

public InputStream getInputStream()
Get an InputStream that represents this file. This is the preferred method of getting file data.

Throws: FileNotFoundException If some sort of file representation cannot be found for the FormFile IOException If there is some sort of IOException

setContentType

public void setContentType(String contentType)
Sets the content type for this file.

NOTE: This method is not supported in this implementation.

Parameters: contentType A string representing the content type.

setFileName

public void setFileName(String fileName)
Sets the (client-side) file name for this file.

NOTE: This method is not supported in this implementation.

Parameters: fileName The client-side name for the file.

setFileSize

public void setFileSize(int filesize)
Sets the size, in bytes, for this file.

NOTE: This method is not supported in this implementation.

Parameters: filesize The size of the file, in bytes.

toString

public String toString()
Returns the (client-side) file name for this file.

Returns: The client-size file name.

Copyright B) 2000-2009 - The Apache Software Foundation