gov.nih.nci.caarray.ui.core
Class CustomCommonsFormFile

java.lang.Object
  extended by gov.nih.nci.caarray.ui.core.CustomCommonsFormFile
All Implemented Interfaces:
CustomFormFile, org.apache.struts.upload.FormFile

public class CustomCommonsFormFile
extends java.lang.Object
implements CustomFormFile

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.


Constructor Summary
CustomCommonsFormFile(org.apache.commons.fileupload.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  java.lang.String getBaseFileName(java.lang.String filePath)
          Returns the base file name from the supplied file path.
 java.lang.String getContentType()
          Returns the content type for this file.
 byte[] getFileData()
          Returns the data for this file as a byte array.
 java.lang.String getFileName()
          Returns the (client-side) file name for this file.
 int getFileSize()
          Returns the size, in bytes, of this file.
 java.io.InputStream getInputStream()
          Get an InputStream that represents this file.
 void setContentType(java.lang.String contentType)
          Sets the content type for this file.
 void setFileName(java.lang.String fileName)
          Sets the (client-side) file name for this file.
 void setFileSize(int filesize)
          Sets the size, in bytes, for this file.
 java.lang.String toString()
          Returns the (client-side) file name for this file.
 void write(java.io.File file)
          Delegates to the org.apache.commons.fileupload.FileItem of the Apache Commons FileUpload framework.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CustomCommonsFormFile

public CustomCommonsFormFile(org.apache.commons.fileupload.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

getContentType

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

Specified by:
getContentType in interface org.apache.struts.upload.FormFile
Returns:
A String representing content type.

setContentType

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

NOTE: This method is not supported in this implementation.

Specified by:
setContentType in interface org.apache.struts.upload.FormFile
Parameters:
contentType - A string representing the content type.

getFileSize

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

Specified by:
getFileSize in interface org.apache.struts.upload.FormFile
Returns:
The size of the file, in bytes.

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 org.apache.struts.upload.FormFile
Parameters:
filesize - The size of the file, in bytes.

getFileName

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

Specified by:
getFileName in interface org.apache.struts.upload.FormFile
Returns:
The client-size file name.

setFileName

public void setFileName(java.lang.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 org.apache.struts.upload.FormFile
Parameters:
fileName - The client-side name for the file.

getFileData

public byte[] getFileData()
                   throws java.io.FileNotFoundException,
                          java.io.IOException
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.

Specified by:
getFileData in interface org.apache.struts.upload.FormFile
Returns:
An array of bytes representing the data contained in this form file.
Throws:
java.io.FileNotFoundException - If some sort of file representation cannot be found for the FormFile
java.io.IOException - If there is some sort of IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
Get an InputStream that represents this file. This is the preferred method of getting file data.

Specified by:
getInputStream in interface org.apache.struts.upload.FormFile
Returns:
input stream for the file
Throws:
java.io.FileNotFoundException - If some sort of file representation cannot be found for the FormFile
java.io.IOException - If there is some sort of IOException

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 org.apache.struts.upload.FormFile

getBaseFileName

protected java.lang.String getBaseFileName(java.lang.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.

toString

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

Overrides:
toString in class java.lang.Object
Returns:
The client-size file name.

write

public void write(java.io.File file)
           throws java.lang.Exception
Delegates to the org.apache.commons.fileupload.FileItem of the Apache Commons FileUpload framework.

Specified by:
write in interface CustomFormFile
Parameters:
file - the new file to write
Throws:
java.lang.Exception - any exceptions raised while writing the new file.