|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.proteios.core.BasicItem<D>
org.proteios.core.OwnedItem<D>
org.proteios.core.SharedItem<D>
org.proteios.core.CommonItem<D>
org.proteios.core.AnnotatedItem<FileData>
org.proteios.core.File
public class File
This class is used to represent individual file items and information about them. This item also handels the physical file on disk. It should work as expected, but under very unfortunate circumstances, ie. an error happens during rollback or commit after the changers has been written to the database, it may not delete all files that should be deleted.
| Nested Class Summary | |
|---|---|
static class |
File.Action
A fileaction describes if a file should be moved to secondary storage or brought back from it. |
| Field Summary | |
|---|---|
static int |
MAX_MIMETYPE_LENGTH
The maximum length of the MIME type that can be stored in the database. |
static int |
MAX_URI_LENGTH
The maximum length of the URI that can be stored in the database. |
static Item |
TYPE
The type of item represented by this class. |
| Fields inherited from interface org.proteios.core.Nameable |
|---|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH |
| Method Summary | |
|---|---|
void |
addBioMaterial(BioMaterial bioMaterial)
Add a BioMaterial |
void |
compress(ProgressReporter progress)
Compress the file if stored on an internal disk. |
void |
decompress(ProgressReporter progress)
Decompress the file if stored on an internal disk. |
void |
download(OutputStream out,
long offset)
Download the physical file for this file item. |
static boolean |
exists(DbControl dc,
Directory directory,
String fileName)
Checks if a file with the specified name exists in the directory. |
File.Action |
getAction()
Get the File.Action of this file. |
Set<BioMaterial> |
getBioMaterials()
|
long |
getCompressedSizeInBytes()
Get the compressed size in bytes of this file. |
Date |
getCreated()
|
Directory |
getDirectory()
Get the associated Directory item. |
InputStream |
getDownloadStream(long offset)
Get an InputStream that can be used to download the
physical file for this file item. |
FileType |
getFileType()
Get the associated FileType item. |
Location |
getLocation()
Get the Location the items is stored at. |
String |
getMd5()
Get the MD5 hash of the file contents, or null if not known. |
String |
getMimeType()
The mimetype of this File. |
Path |
getPath()
Get the complete path of this file. |
static ItemQuery<File> |
getQuery()
Get a query configured to retrieve File items. |
String |
getQuotaTypeSystemId()
Get the QuotaType system id of this item. |
InputStream |
getRawDownloadStream(long offset)
Get an InputStream that can be used to download the
physical file for this file item. |
long |
getSize()
Get the size of this file. |
long |
getSizeInBytes()
Get the (uncompressed) size in bytes of this file. |
Item |
getType()
Get the type of item represented by the object. |
String |
getUniformResourceIdentifier()
|
OutputStream |
getUploadStream(boolean checkMd5)
Get an OutputStream that can be used to upload a physical
file for this file item. |
OutputStream |
getUploadStream(boolean checkMd5,
Boolean compress)
Get an OutputStream that can be used to upload a physical
file for this file item. |
OutputStream |
getUploadStream(boolean checkMd5,
Boolean compress,
boolean append)
Get an OutputStream that can be used to upload a physical
file for this file item. |
boolean |
isCompressed()
If this file is stored in a compressed format or not. |
boolean |
isUsed()
Checks if: A FileAttachable item is using this key. |
void |
setAction(File.Action action)
Set the action of this File item. |
void |
setBioMaterials(Set<BioMaterial> bioMaterials)
Set the BioMaterial bioMaterials set. |
void |
setCompressed(boolean compressed)
Set the flag indicating that this file is stored in a compressed format or not. |
void |
setCompressedSizeInBytes(long size)
Set the compressed size in bytes of this file. |
void |
setDirectory(Directory directory)
Set the directory of this File item. |
void |
setFileType(FileType filetype)
Set the filetype of this File item. |
void |
setLocation(Location location)
Set the location of this File item. |
void |
setMd5(String Md5)
Set the MD5 hash of the file contents. |
void |
setMimeType(String mimeType)
Set the mime type for this File item. |
void |
setMimeTypeAuto(String defaultMimeType)
Set the mime type automatically by checking the extension of the name. |
void |
setName(String name)
Set the name of the item. |
void |
setSizeInBytes(long size)
Set the (uncompressed) size in bytes of this file. |
void |
setUniformResourceIdentifier(String uniformResourceIdentifier)
Set the URI for this File item. |
void |
upload(InputStream in,
boolean checkMd5)
Upload a physical file for this file item. |
void |
upload(InputStream in,
boolean checkMd5,
Boolean compress)
Upload a physical file for this file item. |
| Methods inherited from class org.proteios.core.CommonItem |
|---|
getDescription, getName, isRemoved, setDescription, setRemoved |
| Methods inherited from class org.proteios.core.SharedItem |
|---|
getItemKey, getProjectKey, isShared, setItemKey, setProjectKey |
| Methods inherited from class org.proteios.core.OwnedItem |
|---|
getOwner, setOwner |
| Methods inherited from class org.proteios.core.BasicItem |
|---|
checkPermission, equals, getDbControl, getId, getPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.proteios.core.Ownable |
|---|
getOwner, setOwner |
| Methods inherited from interface org.proteios.core.Identifiable |
|---|
getId, getVersion |
| Methods inherited from interface org.proteios.core.AccessControlled |
|---|
checkPermission, hasPermission |
| Field Detail |
|---|
public static final Item TYPE
ITEM.FILE,
getType()public static final int MAX_URI_LENGTH
setUniformResourceIdentifier(String),
Constant Field Valuespublic static final int MAX_MIMETYPE_LENGTH
setMimeType(String),
Constant Field Values| Method Detail |
|---|
public static boolean exists(DbControl dc,
Directory directory,
String fileName)
throws BaseException
dc - The DbControl which will be used for permission
checking and database access.directory - The directory to check in.fileName - The name of the file to look for.
BaseExceptionpublic static ItemQuery<File> getQuery()
File items.
ItemQuery objectpublic void compress(ProgressReporter progress)
Location.PRIMARY location, the file is compressed
on the disk, otherwise only the "compress" flag is set to `true`, in
order to trigger a requested download stream to be decompressed.
progress - ProgressReporter An optional progress reporter.
PermissionDeniedException - If the logged in user doesn't have
write permission on the file.public void decompress(ProgressReporter progress)
Location.PRIMARY location, the file is
decompressed on the disk, otherwise only the "compress" flag is set to
`false`, in order to trigger a requested download stream to be
unmodified.
progress - ProgressReporter An optional progress reporter.
PermissionDeniedException - If the logged in user doesn't have
write permission on the file.public String getUniformResourceIdentifier()
public void setUniformResourceIdentifier(String uniformResourceIdentifier)
throws InvalidDataException
File item. The value may be null but
must not be longer than the value specified by the
MAX_URI_LENGTH constant.
InvalidDataException - If the URI is longer than
MAX_URI_LENGTH or protocol is different from httppublic Date getCreated()
public Item getType()
IdentifiableItem enumeration.
getType in interface Identifiable
public void setName(String name)
throws PermissionDeniedException,
InvalidDataException
NameableNameable.MAX_NAME_LENGTH constant.
setName in interface NameablesetName in class CommonItem<FileData>name - The new name for the item
PermissionDeniedException - If the logged in user doesn't
have write permission
InvalidDataException - If the name is null or longer
than specified by the Nameable.MAX_NAME_LENGTH constantpublic long getSizeInBytes()
getSizeInBytes in interface DiskConsumablepublic void setSizeInBytes(long size)
size - long The (uncompressed) size in bytes of this file to set.public long getCompressedSizeInBytes()
getSizeInBytes().
public void setCompressedSizeInBytes(long size)
size - long The compressed size in bytes of this file to set.public boolean isCompressed()
public void setCompressed(boolean compressed)
compressed - boolean The flag indicating that this file is stored in
a compressed format.public String getQuotaTypeSystemId()
DiskConsumableQuotaType system id of this item. It is not allowed
to return the QuotaType.TOTAL quota type.
getQuotaTypeSystemId in interface DiskConsumablepublic Location getLocation()
DiskConsumableLocation the items is stored at.
getLocation in interface DiskConsumablepublic void addBioMaterial(BioMaterial bioMaterial)
bioMaterial - The BioMaterial to add to the Set
public Set<BioMaterial> getBioMaterials()
throws ItemNotFoundException,
BaseException
ItemNotFoundException
BaseExceptionpublic void setBioMaterials(Set<BioMaterial> bioMaterials)
BioMaterial bioMaterials set.
bioMaterials - The new Set item.
public boolean isUsed()
throws BaseException
FileAttachable item is using this key.
isUsed in class BasicItem<FileData>BaseException - If there is another error
public FileType getFileType()
throws PermissionDeniedException,
BaseException
FileType item.
FileType item, or null if no type has been
specified
PermissionDeniedException - This exception is thrown if the logged
in user doesn't have READ permission to
the items
BaseException - If there is another error
public void setFileType(FileType filetype)
throws PermissionDeniedException
File item.
filetype - The new FileType, or null
PermissionDeniedException - If the logged in user doesn't have
write permission
public void setLocation(Location location)
throws PermissionDeniedException,
InvalidUseOfNullException
File item.
location - The new Location
PermissionDeniedException - If the logged in user doesn't have
write permission
InvalidUseOfNullException - If location is nullpublic File.Action getAction()
File.Action of this file.
public void setAction(File.Action action)
throws PermissionDeniedException,
InvalidUseOfNullException
File item.
action - The new File.Action
PermissionDeniedException - If the logged in user doesn't have
write permission
InvalidUseOfNullException - If action is nullpublic long getSize()
public String getMd5()
public void setMd5(String Md5)
Md5 - String A 32-character hexadecimal string to set.public String getMimeType()
File. It can be a defined
MimeType , any mimetype or null.
public void setMimeType(String mimeType)
throws PermissionDeniedException,
InvalidDataException
File item. It can be any
mimetype or one avalible in the mimetype table.
mimeType - The new mime type for this item
PermissionDeniedException - If the logged in user doesn't have
write permission
InvalidDataException - If the mime type is longer than
MAX_MIMETYPE_LENGTH
public Directory getDirectory()
throws PermissionDeniedException,
BaseException
Directory item.
Directory item
PermissionDeniedException - This exception is thrown if the logged
in user doesn't have READ permission to
the items
BaseException - If there is another error
public void setDirectory(Directory directory)
throws PermissionDeniedException,
InvalidUseOfNullException
File item.
directory - The new Directory
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission to the file or
Permission.USE permission to the directory
InvalidUseOfNullException - If directory is nullpublic Path getPath()
Path object
public void setMimeTypeAuto(String defaultMimeType)
throws PermissionDeniedException
defaultMimeType - The default value to use if no match is found for
the file extension
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission
public void upload(InputStream in,
boolean checkMd5)
throws PermissionDeniedException,
BaseException
in - An InputStream which will be read until end of
file is foundcheckMd5 - If the MD5 sum of the uploaded data should be checked
against the MD5 sum already stored in the database. If no MD5
exists in the database this parameter is ignored
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission for this item
BaseException - If there is another error
public void upload(InputStream in,
boolean checkMd5,
Boolean compress)
throws PermissionDeniedException,
BaseException
in - An InputStream which will be read until end of
file is foundcheckMd5 - If the MD5 sum of the uploaded data should be checked
against the MD5 sum already stored in the database. If no MD5
exists in the database this parameter is ignoredcompress - Boolean TRUE to store the file in a compressed format.
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission for this item
BaseException - If there is another error
public OutputStream getUploadStream(boolean checkMd5)
throws PermissionDeniedException,
BaseException
OutputStream that can be used to upload a physical
file for this file item. The client application should call
close() method to finish the upload. If the file exists it
will be overwritten.
checkMd5 - If the MD5 sum of the uploaded data should be checked
against the MD5 sum already stored in the database. If no MD5
exists in the database this parameter is ignored
OutputStream object
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission for this item
BaseException - If there is another error
public OutputStream getUploadStream(boolean checkMd5,
Boolean compress)
throws PermissionDeniedException,
BaseException
OutputStream that can be used to upload a physical
file for this file item. The client application should call
close() method to finish the upload. If the file exists it
will be overwritten.
checkMd5 - If the MD5 sum of the uploaded data should be checked
against the MD5 sum already stored in the database. If no MD5
exists in the database this parameter is ignoredcompress - Boolean Whether the file will be stored in compressed
format or not.
OutputStream object
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission for this item
BaseException - If there is another error
public OutputStream getUploadStream(boolean checkMd5,
Boolean compress,
boolean append)
throws PermissionDeniedException,
BaseException
OutputStream that can be used to upload a physical
file for this file item. The client application should call
close() method to finish the upload.
checkMd5 - If the MD5 sum of the uploaded data should be checked
against the MD5 sum already stored in the database. If no MD5
exists in the database this parameter is ignoredcompress - Boolean Whether the file will be stored in compressed
format or not.append - boolean Whether the stream will be appended to an existing
file or not. If there is no existing file this parameter has no
effect.
OutputStream object
PermissionDeniedException - If the logged in user doesn't have
Permission.WRITE permission for this item
BaseException - If there is another error
public void download(OutputStream out,
long offset)
throws BaseException
out - An OutputStream object which will be used to
write the fileoffset - Start reading the physical at the specified offset, use 0
to start reading from the beginning
BaseException - If there is an error
public InputStream getDownloadStream(long offset)
throws BaseException
InputStream that can be used to download the
physical file for this file item. The client application should call
close() method to finish the download. If the physical
file isn't at the primary location there is an attempt at downloading the
file from the URI. If no URI is given an empty stream is returned.
offset - Start reading the physical at the specified offset, use 0
to start reading from the beginning
InputStream object
BaseException - If there is an error
public InputStream getRawDownloadStream(long offset)
throws BaseException
InputStream that can be used to download the
physical file for this file item. The client application should call
close() method to finish the download. If the physical
file isn't at the primary location there is an attempt at downloading the
file from the URI. If no URI is given an empty stream is returned. Does
not attempt to decompress contents of a file stored compressed
internally.
offset - Start reading the physical at the specified offset, use 0
to start reading from the beginning
InputStream object
BaseException - If there is an error
|
Last update: 2011-06-23 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||