public class StorageObject extends BaseStorageItem implements java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
protected AccessControlList |
acl |
protected java.lang.String |
bucketName |
protected java.io.File |
dataInputFile
Store references to files when the object's data comes from a file, to allow for lazy
opening of the file's input streams.
|
protected java.io.InputStream |
dataInputStream |
protected boolean |
isMetadataComplete |
static java.lang.String |
METADATA_HEADER_HASH_MD5 |
static java.lang.String |
METADATA_HEADER_ORIGINAL_HASH_MD5 |
static java.lang.String |
METADATA_HEADER_SERVER_SIDE_ENCRYPTION |
protected java.lang.String |
serverSideEncryptionAlgorithm |
protected java.lang.String |
storageClass |
METADATA_HEADER_CONTENT_DISPOSITION, METADATA_HEADER_CONTENT_ENCODING, METADATA_HEADER_CONTENT_LANGUAGE, METADATA_HEADER_CONTENT_LENGTH, METADATA_HEADER_CONTENT_MD5, METADATA_HEADER_CONTENT_TYPE, METADATA_HEADER_CREATION_DATE, METADATA_HEADER_DATE, METADATA_HEADER_ETAG, METADATA_HEADER_LAST_MODIFIED_DATE
Constructor and Description |
---|
StorageObject()
Create an object without any associated information whatsoever.
|
StorageObject(java.io.File file)
Create an object representing a file.
|
StorageObject(java.lang.String key)
Create an object without any associated data.
|
StorageObject(java.lang.String key,
byte[] data)
Create an object representing binary data.
|
StorageObject(java.lang.String key,
java.lang.String dataString)
Create an object representing text data.
|
Modifier and Type | Method and Description |
---|---|
void |
addAllMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)
Add all the metadata information to the object from the provided map.
|
void |
addMetadata(java.lang.String name,
java.lang.String value)
Add metadata information to the object.
|
java.lang.Object |
clone() |
void |
closeDataInputStream()
Closes the object's data input stream if it exists.
|
AccessControlList |
getAcl() |
java.lang.String |
getBucketName() |
java.lang.String |
getContentDisposition() |
java.lang.String |
getContentEncoding() |
java.lang.String |
getContentLanguage() |
long |
getContentLength() |
java.lang.String |
getContentType() |
java.io.File |
getDataInputFile() |
java.io.InputStream |
getDataInputStream()
Returns an input stream containing this object's data, or null if there is
no data associated with the object.
|
java.lang.String |
getETag() |
java.lang.String |
getKey() |
java.util.Date |
getLastModifiedDate() |
java.lang.String |
getMd5HashAsBase64() |
java.lang.String |
getMd5HashAsHex() |
java.util.Map<java.lang.String,java.lang.Object> |
getModifiableMetadata()
Returns only those object metadata items that can be modified in
a service.
|
java.lang.String |
getServerSideEncryptionAlgorithm() |
java.lang.String |
getStorageClass() |
boolean |
isDirectoryPlaceholder() |
boolean |
isMetadataComplete() |
void |
setAcl(AccessControlList acl)
Set the object's ACL.
|
void |
setBucketName(java.lang.String bucketName)
Set the name of the bucket this object belongs to or will be placed into.
|
void |
setContentDisposition(java.lang.String contentDisposition)
Set the content disposition of the object.
|
void |
setContentEncoding(java.lang.String contentEncoding)
Set the content encoding of this object.
|
void |
setContentLanguage(java.lang.String contentLanguage)
Set the content language of the object.
|
void |
setContentLength(long size)
Set this object's content length.
|
void |
setContentType(java.lang.String contentType)
Set the content type of the object.
|
void |
setDataInputFile(java.io.File dataInputFile)
Sets the file containing the data content to associate with this object.
|
void |
setDataInputStream(java.io.InputStream dataInputStream)
Sets an input stream containing the data content to associate with this object.
|
void |
setETag(java.lang.String etag)
Set the ETag value of the object based on information returned from the service.
|
void |
setKey(java.lang.String key)
Set the key of this object.
|
void |
setLastModifiedDate(java.util.Date lastModifiedDate)
Set this object's last modified date based on information returned from the service.
|
void |
setMd5Hash(byte[] md5Hash)
Set the MD5 hash value of this object's data.
|
void |
setMetadataComplete(boolean isMetadataComplete)
Object metadata are only complete when it is populated with all values following
a HEAD or GET request.
|
void |
setServerSideEncryptionAlgorithm(java.lang.String serverSideEncryptionAlgorithm)
Set the encryption algorithm to use for server-side encryption of this object
(will be unencrypted if set to null)
|
void |
setStorageClass(java.lang.String storageClass)
Set the storage class for this object.
|
java.lang.String |
toString() |
boolean |
verifyData(byte[] downloadedData)
Calculates the MD5 hash value of the given data object, and compares it
against this object's hash (as stored in the Content-MD5 header for
uploads, or the ETag header for downloads).
|
boolean |
verifyData(java.io.File downloadedFile)
Calculates the MD5 hash value of the given data object, and compares it
against this object's hash (as stored in the Content-MD5 header for
uploads, or the ETag header for downloads).
|
boolean |
verifyData(java.io.InputStream downloadedDataStream)
Calculates the MD5 hash value of the given data object, and compares it
against this object's hash (as stored in the Content-MD5 header for
uploads, or the ETag header for downloads).
|
addMetadata, addMetadata, addMetadata, containsMetadata, getCompleteMetadataMap, getHttpMetadata, getHttpMetadataMap, getMetadata, getMetadataCaseInsensitiveFromMap, getMetadataMap, getName, getOwner, getServiceMetadata, getServiceMetadataMap, getUserMetadata, getUserMetadataMap, isMatchingMetadataName, lookupMetadataSubsetMap, removeMetadata, replaceAllMetadata, setName, setOwner
public static final java.lang.String METADATA_HEADER_HASH_MD5
public static final java.lang.String METADATA_HEADER_ORIGINAL_HASH_MD5
public static final java.lang.String METADATA_HEADER_SERVER_SIDE_ENCRYPTION
protected AccessControlList acl
protected transient java.io.InputStream dataInputStream
protected boolean isMetadataComplete
protected java.lang.String bucketName
protected java.lang.String storageClass
protected java.lang.String serverSideEncryptionAlgorithm
protected java.io.File dataInputFile
public StorageObject(java.io.File file) throws java.security.NoSuchAlgorithmException, java.io.IOException
Mimetypes
), and a content length matching the file's size.
The file's MD5 hash value is also calculated and provided to the destination service,
so the service can verify that no data are corrupted in transit.
NOTE: The automatic calculation of a file's MD5 hash digest as performed by this constructor could take some time for large files, or for many small ones.
file
- the file the object will represent. This file must exist and be readable.java.io.IOException
- when an i/o error occurred reading the filejava.security.NoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(java.lang.String key, java.lang.String dataString) throws java.security.NoSuchAlgorithmException, java.io.IOException
text/plain; charset=utf-8
, and a content length matching the
string's length.
The given string's MD5 hash value is also calculated and provided to the target
service, so the service can verify that no data are corrupted in transit.
NOTE: The automatic calculation of the MD5 hash digest as performed by this constructor could take some time for large strings, or for many small ones.
key
- the key name for the object.dataString
- the text data the object will contain. Text data will be encoded as UTF-8.
This string cannot be null.java.io.IOException
java.security.NoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(java.lang.String key, byte[] data) throws java.security.NoSuchAlgorithmException, java.io.IOException
application/octet-stream
, and a content length matching the
byte array's length.
The MD5 hash value of the byte data is also calculated and provided to the target
service, so the service can verify that no data are corrupted in transit.key
- the key name for the object.data
- the byte data the object will contain, cannot be null.java.io.IOException
java.security.NoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(java.lang.String key)
key
- the key name for the object.public StorageObject()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getBucketName()
public void setBucketName(java.lang.String bucketName)
bucketName
- the name for the bucket.public java.io.InputStream getDataInputStream() throws ServiceException
If you are downloading data from a service, you should consider verifying the
integrity of the data you read from this stream using one of the
verifyData(InputStream)
methods.
ServiceException
public void setDataInputStream(java.io.InputStream dataInputStream)
Note: If the data content comes from a file, use the alternate method
setDataInputFile(File)
which allows objects to lazily open files and avoid any
Operating System limits on the number of files that may be opened simultaneously.
Note 2: This method does not calculate an MD5 hash of the input data,
which means the target service will not be able to recognize if data are corrupted in transit.
To allow the target service to verify data you upload, you should set the MD5 hash value of
your data using setMd5Hash(byte[])
.
This method will set the object's file data reference to null.
dataInputStream
- an input stream containing the object's data.public void setDataInputFile(java.io.File dataInputFile)
getDataInputStream()
is called.
Note 2: This method does not calculate an MD5 hash of the input data,
which means the target service will not be able to recognize if data are corrupted in transit.
To allow the target service to verify data you upload, you should set the MD5 hash value of
your data using setMd5Hash(byte[])
.
This method will set the object's input stream data reference to null.
dataInputFile
- a file containing the object's data.public java.io.File getDataInputFile()
public void closeDataInputStream() throws java.io.IOException
java.io.IOException
public java.lang.String getETag()
public void setETag(java.lang.String etag)
etag
- the ETag value as provided by the service.public java.lang.String getMd5HashAsHex()
md5-hash
, or null if the hash value is not available.public java.lang.String getMd5HashAsBase64()
Content-MD5
, or as derived from an ETag
or
md5-hash
hex-encoded version of the hash. Returns null if the hash value is not
available.public void setMd5Hash(byte[] md5Hash)
Content-MD5
(Base64-encoded)
and the JetS3t-specific md5-hash
(Hex-encoded).md5Hash
- the MD5 hash value of the object's data.public java.util.Date getLastModifiedDate()
public void setLastModifiedDate(java.util.Date lastModifiedDate)
lastModifiedDate
- public long getContentLength()
public void setContentLength(long size)
setDataInputStream(InputStream)
or setDataInputFile(File)
methods,
you must also set the content length value.size
- public java.lang.String getContentType()
public void setContentType(java.lang.String contentType)
Mimetypes
).
You should set the content type for associated String or InputStream data.contentType
- public java.lang.String getContentLanguage()
public void setContentLanguage(java.lang.String contentLanguage)
contentLanguage
- public java.lang.String getContentDisposition()
public void setContentDisposition(java.lang.String contentDisposition)
contentDisposition
- public java.lang.String getContentEncoding()
public void setContentEncoding(java.lang.String contentEncoding)
contentEncoding
- public java.lang.String getKey()
public void setKey(java.lang.String key)
key
- the key for this object.public AccessControlList getAcl()
public void setAcl(AccessControlList acl)
acl
- public java.lang.String getStorageClass()
public void setStorageClass(java.lang.String storageClass)
storageClass
- public java.lang.String getServerSideEncryptionAlgorithm()
public void setServerSideEncryptionAlgorithm(java.lang.String serverSideEncryptionAlgorithm)
serverSideEncryptionAlgorithm
- public boolean isMetadataComplete()
public void setMetadataComplete(boolean isMetadataComplete)
isMetadataComplete
- public void addMetadata(java.lang.String name, java.lang.String value)
addMetadata
in class BaseStorageItem
name
- value
- public void addAllMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)
addAllMetadata
in class BaseStorageItem
metadata
- public java.util.Map<java.lang.String,java.lang.Object> getModifiableMetadata()
public boolean isDirectoryPlaceholder()
public boolean verifyData(java.io.File downloadedFile) throws java.security.NoSuchAlgorithmException, java.io.FileNotFoundException, java.io.IOException
downloadedFile
- java.lang.IllegalStateException
- if the object's MD5 hash value is unavailable, e.g. for objects stored
in S3 using multipart uploads (for which the service does not provide
MD5 hash values for verification).java.security.NoSuchAlgorithmException
java.io.FileNotFoundException
java.io.IOException
public boolean verifyData(byte[] downloadedData) throws java.security.NoSuchAlgorithmException, java.io.FileNotFoundException, java.io.IOException
downloadedData
- java.security.NoSuchAlgorithmException
java.io.FileNotFoundException
java.io.IOException
public boolean verifyData(java.io.InputStream downloadedDataStream) throws java.security.NoSuchAlgorithmException, java.io.FileNotFoundException, java.io.IOException
downloadedDataStream
- the input stream of a downloaded object.java.security.NoSuchAlgorithmException
java.io.FileNotFoundException
java.io.IOException