org.apache.struts.upload

Class CommonsMultipartRequestHandler.CommonsFormFile

Enclosing Class:
CommonsMultipartRequestHandler
Implemented Interfaces:
FormFile, Serializable

(package private) static class CommonsMultipartRequestHandler.CommonsFormFile
extends java.lang.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

(package private) FileItem
fileItem
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

void
destroy()
Destroy all content for this form file.
protected String
getBaseFileName(String filePath)
Returns the base file name from the supplied file path.
String
getContentType()
Returns the content type for this file.
byte[]
getFileData()
Returns the data for this file as a byte array.
String
getFileName()
Returns the (client-side) file name for this file.
int
getFileSize()
Returns the size, in bytes, of this file.
InputStream
getInputStream()
Get an InputStream that represents this file.
void
setContentType(String contentType)
Sets the content type for this file.
void
setFileName(String fileName)
Sets the (client-side) file name for this file.
void
setFileSize(int filesize)
Sets the size, in bytes, for this file.
String
toString()
Returns the (client-side) file name for this file.

Field Details

fileItem

(package private)  FileItem fileItem
The FileItem instance wrapped by this object.

Constructor Details

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 Details

destroy

public void destroy()
Destroy all content for this form file. Implementations should remove any temporary files or any temporary file data stored somewhere
Specified by:
destroy in interface FormFile

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.
Specified by:
getContentType in interface FormFile
Returns:
A String representing content type.

getFileData

public byte[] getFileData()
            throws FileNotFoundException,
                   IOException
Specified by:
getFileData in interface FormFile
Returns:
An array of bytes representing the data contained in this form file.

getFileName

public String getFileName()
Returns the (client-side) file name for this file.
Specified by:
getFileName in interface FormFile
Returns:
The client-size file name.

getFileSize

public int getFileSize()
Returns the size, in bytes, of this file.
Specified by:
getFileSize in interface FormFile
Returns:
The size of the file, in bytes.

getInputStream

public InputStream getInputStream()
            throws FileNotFoundException,
                   IOException
Get an InputStream that represents this file. This is the preferred method of getting file data.
Specified by:
getInputStream in interface FormFile

setContentType

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

NOTE: This method is not supported in this implementation.

Specified by:
setContentType in interface FormFile
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.

Specified by:
setFileName in interface FormFile
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.

Specified by:
setFileSize in interface FormFile
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-2007 - The Apache Software Foundation