This package allows you to change the file relative behaviour: this page describes how to override the default behaviour, to fullfill your needs (for instance add data compression, preload check, new data about files in the upload to the server..

What is FileData for ?

The FileData interface provides an easy way to add new file type capabilities to the applet. The main entry points allow you to:
  • Change the file behaviour for the upload. For instance: additional checks, compression before upload, new file properties to be sent to the server.
  • New GUI capabilities: for instance an AudioFileData has been started, to allow the user to hear the sound in the files he selected.
  • HowTo create a new FileData instance

    The core/default implementation is contained in DefaultFileData. This class provides a default implementation to all FileData interface methods. The easiest way to create a new FileData instance, is to inherit from this default implementation, and just override the method you're interested in. Doing this minimizes your work, and insures you the minimum risk of incompatibility with next versions.
    Once you've created your new XxxFileData class, you'll have to create objects of this class. This is done by creating a new {@link wjhk.jupload2.policies.UploadPolicy}, and override the {@link wjhk.jupload2.policies.UploadPolicy#createFileData(java.io.File, java.io.File)} method.

    Description of FileData methods

    Methods with impact on upload behaviour or content

    {@link wjhk.jupload2.filedata.FileData#appendFileProperties(ByteArrayEncoder, int)} Add properties like the filename, or the directory to the upload (useless in FTP mode)
    {@link wjhk.jupload2.filedata.FileData#beforeUpload()} Allows the FileData to do any necessary work before the upload of the file begin. For instance, in PictureFileData, the picture can here be resized, according to the upload policies values.
    {@link wjhk.jupload2.filedata.FileData#getUploadLength()} Returns the actual number of bytes that will be uploaded. Will be different from the file length, if the file must transformed before upload. For instance: picture resizing, or before upload compression.
    {@link wjhk.jupload2.filedata.FileData#afterUpload()} Called after the end of the upload. Allows to clear any resource, like temporary files.
    {@link wjhk.jupload2.filedata.FileData#getInputStream()} Returns an InputStream, that'll contain all bytes to upload.

    Methods for general file information

    You probably won't have to override these methods.
  • {@link wjhk.jupload2.filedata.FileData#getFileExtension()}
  • {@link wjhk.jupload2.filedata.FileData#getFileLength()}
  • {@link wjhk.jupload2.filedata.FileData#getLastModified()}
  • {@link wjhk.jupload2.filedata.FileData#getDirectory()}
  • {@link wjhk.jupload2.filedata.FileData#getMimeType()}
  • {@link wjhk.jupload2.filedata.FileData#canRead()}
  • {@link wjhk.jupload2.filedata.FileData#getFile()}
  • {@link wjhk.jupload2.filedata.FileData#getRelativeDir()}: Returns the directory, relative to the current selection. Especially useful when dropping entire directories on the applet.