com.gentics.api.lib.upload
Class FileInformation

java.lang.Object
  extended by com.gentics.api.lib.resolving.ResolvableBean
      extended by com.gentics.api.lib.upload.FileInformation
All Implemented Interfaces:
Resolvable, java.io.Serializable

public class FileInformation
extends ResolvableBean

Provides information about an uploaded file.

See Also:
Serialized Form

Constructor Summary
FileInformation(java.io.File file)
          Create an instance of fileinformation based on the given file.
FileInformation(org.apache.commons.fileupload.FileItem myFileItem, FileUploadProvider fileUploadProvider)
          Create a FileInformation object base of the given FileItem
FileInformation(java.lang.String fileName, long fileSize, java.lang.String contentType, byte[] fileData)
          Create a FileInformation object with preset data
FileInformation(java.lang.String fileName, long fileSize, java.lang.String contentType, byte[] fileData, java.io.File file, boolean deleteFileOnInvalidate)
          Create an instance of fileinformation
 
Method Summary
 FileInformation cloneFileInformation()
          Can be used to retrieve a clone of a file item if it is needed longer than one request long.
protected  void finalize()
          Called by the GC - invalidates this instance to delete tmp files.
 java.lang.String getContentType()
          Returns the delivered ContentType of the File
 java.lang.String getFileName()
          Returns the relative Path of the File.
 java.lang.String getFilePath()
          Returns the upload Path if available or null if not.
 long getFileSize()
          Get the file size in bytes.
 java.io.InputStream getInputStream()
          Get an input stream for reading the content of an uploaded file
 java.lang.String getOriginalFileName()
          Returns the "original" filename which was passed by the browser.
 void invalidate()
          Invalidates this instance of FileInformation.
 
Methods inherited from class com.gentics.api.lib.resolving.ResolvableBean
canResolve, get, getProperty
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileInformation

public FileInformation(java.lang.String fileName,
                       long fileSize,
                       java.lang.String contentType,
                       byte[] fileData)
Create a FileInformation object with preset data

Parameters:
fileName - name of the file
fileSize - size of the file
contentType - content type
fileData - file data as byte array

FileInformation

public FileInformation(org.apache.commons.fileupload.FileItem myFileItem,
                       FileUploadProvider fileUploadProvider)
Create a FileInformation object base of the given FileItem

Parameters:
myFileItem - file item

FileInformation

public FileInformation(java.lang.String fileName,
                       long fileSize,
                       java.lang.String contentType,
                       byte[] fileData,
                       java.io.File file,
                       boolean deleteFileOnInvalidate)
Create an instance of fileinformation

Parameters:
fileName - filename
fileSize - filesize
contentType - contenttype
fileData - filedata
file - file
deleteFileOnInvalidate - true when the file will be deleted, false if not

FileInformation

public FileInformation(java.io.File file)
Create an instance of fileinformation based on the given file. The file will not be deleted on invalidate().

Parameters:
file - file
Method Detail

finalize

protected void finalize()
Called by the GC - invalidates this instance to delete tmp files.

Overrides:
finalize in class java.lang.Object

getFileSize

public final long getFileSize()
Get the file size in bytes.

Returns:
file size in bytes

getContentType

public final java.lang.String getContentType()
Returns the delivered ContentType of the File

Returns:
contentType

getOriginalFileName

public final java.lang.String getOriginalFileName()
Returns the "original" filename which was passed by the browser. (E.g. Opera / IE will give you the full path name, while firefox only sends the file name)

Returns:
filename as sent by the browser/client.

getFileName

public final java.lang.String getFileName()
Returns the relative Path of the File. Take care -> currently MacOS delivers only relative Paths relative path? shouldn't this be the only the filename, without path? TODO this method should be the solution to this problem, by astrahating this, so applications don't have to take care of that.

Returns:
name of the uploaded file

getFilePath

public final java.lang.String getFilePath()
Returns the upload Path if available or null if not. Currently Windows sends the complete path in the HTTP request, while MacOS does not. Unsure about other Systems. Unix is supposed to send only relative paths, but it is not clarified if this is correct.

Returns:
filePath

getInputStream

public final java.io.InputStream getInputStream()
                                         throws java.io.IOException
Get an input stream for reading the content of an uploaded file

Returns:
input stream or null if no data available
Throws:
java.io.IOException

cloneFileInformation

public FileInformation cloneFileInformation()
                                     throws java.io.IOException
Can be used to retrieve a clone of a file item if it is needed longer than one request long.

Returns:
a temporary file with the content of the uploaded file. (null if an error occurred.)
Throws:
java.io.IOException

invalidate

public void invalidate()
Invalidates this instance of FileInformation. (ie. deletes temp files, unreferences memory buffer, etc.)



Copyright © 2013 Gentics Software GmbH. All Rights Reserved.