public class DefaultFileData extends Object implements FileData
UploadPolicy
contains the necessary parameters * to personalize the way files must be
handled. DefaultUploadPolicy
. It provides standard control on the files chosen for upload.FileData
Modifier and Type | Field and Description |
---|---|
protected Boolean |
canRead
Indicates whether the applet can read this file or not.
|
protected File |
file
file is the file about which this FileData contains data.
|
protected String |
fileDir
Cached file directory
|
protected Date |
fileModified
Cached file modification time.
|
protected String |
fileRoot
cached root of this file.
|
protected long |
fileSize
Cached file size
|
protected String |
md5sum
The md5sum for the prepared file.
|
protected String |
mimeType
Mime type of the file.
|
protected boolean |
uploadFlag
Indicated whether this file should be uploaded or not.
|
Constructor and Description |
---|
DefaultFileData(File file,
UploadPolicy uploadPolicyParam)
Standard constructor
|
Modifier and Type | Method and Description |
---|---|
void |
afterUpload()
This function is called after upload, whether it is successful or not.
|
void |
appendFileProperties(ByteArrayEncoder bae,
int index)
Called during the upload, by the
FileUploadThread . |
void |
beforeUpload(String uploadFileRoot)
Prepare the fileData to upload.
|
void |
calculateMD5Sum()
Calculate the MD5Sum for the transformed file, or the original if no transformation should be done on the file,
before upload.
|
boolean |
canRead()
Indicate if this file can be read.
|
String |
getAbsolutePath()
Returns the absolute path, as it will be sent during the upload.
|
String |
getDirectory()
Get the directory of the file.
|
static String |
getExtension(String filename)
Returns the extension of the given file.
|
protected 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 |
getMD5()
Retrieves the MD5 sum of the file.
|
String |
getMimeType()
This function return the FileData content type.
|
String |
getRelativeDir()
Retrieves the path of this file relative to the root directory
|
static File |
getRoot(List<? extends FileData> rows)
Return the 'biggest' common ancestror of the given file array.
|
TreeFileDataNode |
getTreeFileDataNode()
Links this FileData to the associated
TreeFileDataNode , from the hierarchical view. |
boolean |
getUploadFlag()
Indicates whether the check box is checked or not.
|
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.
|
void |
setTreeFileDataNode(TreeFileDataNode treeFileDataNode)
Setters for the to the associated
TreeFileDataNode , from the hierarchical view. |
void |
setUploadFlag(boolean uploadFlag)
Allows to set or unset the upload flag.
|
protected String mimeType
protected File file
protected long fileSize
protected String fileDir
protected String fileRoot
protected Date fileModified
protected boolean uploadFlag
protected String md5sum
#beforeUpload()
, and cleared in the
afterUpload()
.protected Boolean canRead
public DefaultFileData(File file, UploadPolicy uploadPolicyParam)
file
- The file whose data this instance will give.absoluteRoot
- The directory root, to be able to calculate the result of getRelativeDir()
uploadPolicyParam
- The current upload policy.public void appendFileProperties(ByteArrayEncoder bae, int index) throws JUploadIOException
FileUploadThread
. The FileData instance should then call the
ByteArrayEncoder.appendTextProperty(String, String, int)
method to add each file property to the current
upload.appendFileProperties
in interface FileData
bae
- The byte encoder, where the properties must be addedindex
- Index of the file concerned by this value. -1 if this is a global parameter.JUploadIOException
- Encapsulation of the IOException, if any would occurs.ByteArrayEncoder.appendTextProperty(String, String, int)
public void beforeUpload(String uploadFileRoot) throws JUploadException
PictureFileData
. This method is called before the upload of this file. If no exception is thrown, then
the file is correctly prepared.beforeUpload
in interface FileData
uploadFileRoot
- The biggest path which is common to all uploaded files. Used to calculate the relativeDir
to this root path, for each file. This relative path is sent as metadata during the uploadJUploadException
- Encapsulation of the Exception, if any error would occurs.FileUploadThread
,
FileData.getRelativeDir()
public long getUploadLength()
#beforeUpload()
and before the call to FileData.afterUpload()
.getUploadLength
in interface FileData
PictureFileData
public void afterUpload()
PictureFileData.afterUpload()
removes the temporary file, if any
was created.afterUpload
in interface FileData
public InputStream getInputStream() throws JUploadException
FileUploadThread
class then reads bytes from it
and transfers them to the webserver. The caller is responsible for closing this stream.FileData.isPreparedForUpload()
returns true.getInputStream
in interface FileData
JUploadException
- Encapsulation of the Exception, if any would occurs.public String getFileName()
getFileName
in interface FileData
public String getFileExtension()
getFileExtension
in interface FileData
public long getFileLength()
getFileLength
in interface FileData
public Date getLastModified()
getLastModified
in interface FileData
public String getDirectory()
getDirectory
in interface FileData
public boolean getUploadFlag()
getUploadFlag
in interface FileData
public void setUploadFlag(boolean uploadFlag)
setUploadFlag
in interface FileData
public String getMD5() throws JUploadException
getMD5
in interface FileData
JUploadException
#beforeUpload()
public void calculateMD5Sum() throws JUploadException
JUploadException
public String getMimeType()
getMimeType
in interface FileData
public boolean canRead()
protected File getFile()
FileData
interface. Direct link between the DefaultFile
and the File should be avoided. This is especially true to access the file path. You should the other method of
this interface, instead of this one. Typically, using this method is incompatible with the
TreeViewUploadPolicy
getAbsolutePath()
method.public String getRelativeDir()
getRelativeDir
in interface FileData
public String getAbsolutePath()
getAbsolutePath
in interface FileData
public static String getExtension(String filename)
file
- the file whose the extension is wanted!public static File getRoot(List<? extends FileData> rows)
rows
- public boolean isPreparedForUpload()
#beforeUpload()
, and the to false in the call to FileData.afterUpload()
.isPreparedForUpload
in interface FileData
public TreeFileDataNode getTreeFileDataNode()
FileData
TreeFileDataNode
, from the hierarchical view.getTreeFileDataNode
in interface FileData
public void setTreeFileDataNode(TreeFileDataNode treeFileDataNode)
TreeFileDataNode
, from the hierarchical view. Allows link between the
flat and hierarchical view.setTreeFileDataNode
in interface FileData
Copyright © 2015. All rights reserved.