wjhk.jupload2.filedata
Interface FileData

All Known Implementing Classes:
AudioFileData, DefaultFileData, PictureFileData, UploadFileData

public interface FileData

This class contains all data and methods for a file to upload. The current UploadPolicy contains the necessary parameters to personalize the way files must be handled.
The JUpload package provides a default implementation of this class in DefaultFileData. This default implementation contains all necessary methods to allow upload. You can override it to add new file behaviour. For instance, you could add a XMLFileData, that would check that XML is valid before upload. See the package summary for more details about that.
This class is the interface that all FileData must implement. The DefaultFileData class contains the default implementation for this interface. The PictureFileData contains another implementation of this interface, adapted to manage pictures (rotation, resizing...).
The instance of FileData is created by the UploadPolicy.createFileData(File, File) method. This method can be overrided in a new upoad policy, to create an instance of another FileData. See PictureFileData for an example about FileData customization.

Author:
etienne_sf

Method Summary
 void afterUpload()
          This function is called after upload, whether it is successful or not.
 void appendFileProperties(wjhk.jupload2.upload.helper.ByteArrayEncoder bae, int index)
          Called during the upload, by the FileUploadThread.
 void beforeUpload()
          Prepare the fileData to upload.
 boolean canRead()
          Indicate if this file can be read.
 String getDirectory()
          Get the directory of the file.
 File getFile()
          Standard getter, for the file described by the FileData instance.
 String getFileExtension()
           
 long getFileLength()
           
 String getFileName()
          Get the original filename.
 InputStream getInputStream()
          This function creates an InputStream from this file.
 Date getLastModified()
           
 String getMimeType()
          This function return the FileData content type.
 String getRelativeDir()
          Retrieves the path of this file relative to it's root dir
 long getUploadLength()
          Get size of upload, which may be different from the actual file length.
 boolean isPreparedForUpload()
          Indicates whether the file can be uploaded or not.
 

Method Detail

appendFileProperties

void appendFileProperties(wjhk.jupload2.upload.helper.ByteArrayEncoder bae,
                          int index)
                          throws JUploadIOException
Called during the upload, by the FileUploadThread. The FileData instance should then call the ByteArrayEncoder.appendTextProperty(String, String, int) method to add each file property to the current upload.

Parameters:
bae - The byte encoder, where the properties must be added
index - Index of the file concerned by this value. -1 if this is a global parameter.
Throws:
JUploadIOException - Encapsulation of the IOException, if any would occurs.
See Also:
ByteArrayEncoder.appendTextProperty(String, String, int)

beforeUpload

void beforeUpload()
                  throws JUploadException
Prepare the fileData to upload. For instance, picture data can be resized before upload (see PictureFileData. This method is called before the upload of this file.

Throws:
JUploadException - Encapsulation of the Exception, if any would occurs.
See Also:
FileUploadThread

getUploadLength

long getUploadLength()
                     throws JUploadException
Get size of upload, which may be different from the actual file length. This call is valid only after a call to beforeUpload() and before the call to afterUpload().

Returns:
The length of upload. In this class, this is the size of the file, as it isn't transformed for upload. This size may change if encoding is necessary (needs a new FileData class), or if picture is to be resized or rotated.
Throws:
JUploadException - Encapsulation of the Exception, if any would occurs.
See Also:
PictureFileData

afterUpload

void afterUpload()
This function is called after upload, whether it is successful or not. It allows fileData to free any resource created for the upload. For instance, PictureFileData.afterUpload() removes the temporary file, if any was created.


getInputStream

InputStream getInputStream()
                           throws JUploadException
This function creates an InputStream from this file. The FileUploadThread class then reads bytes from it and transfers them to the webserver. The caller is responsible for closing this stream.
This method may only be called when isPreparedForUpload() returns true.

Returns:
An InputStream, representing this instance.
Throws:
JUploadException - Encapsulation of the Exception, if any would occurs.
IllegalStateException - When the upload is not prepared (before a call to beforeUpload() or after a call to afterUpload()

getFileName

String getFileName()
Get the original filename. This is the name of the file, into the local hardrive

Returns:
The original filename

getFileExtension

String getFileExtension()
Returns:
The extension for the original file.

getFileLength

long getFileLength()
Returns:
The length of the original file.

getLastModified

Date getLastModified()
Returns:
The original file date.

getDirectory

String getDirectory()
Get the directory of the file.

Returns:
The directory where this file is stored.

getMimeType

String getMimeType()
This function return the FileData content type.

Returns:
The mimeType for the file.

canRead

boolean canRead()
Indicate if this file can be read. Take care of the File.canRead() methods, that seems to be wrong from time to time.

Returns:
indicates whether the file can be read or not.

getFile

File getFile()
Standard getter, for the file described by the FileData instance.

Returns:
the File instance associated with this row.

getRelativeDir

String getRelativeDir()
Retrieves the path of this file relative to it's root dir

Returns:
This instance's relative path or an empty string if it was not created using a root parameter.

isPreparedForUpload

boolean isPreparedForUpload()
Indicates whether the file can be uploaded or not. This boolean should be set to true in the call to beforeUpload(), and the to false in the call to afterUpload().

Returns:
True if the file is ready for upload.
Throws:
IllegalStateException - When the upload is not prepared (before a call to beforeUpload() or after a call to afterUpload()