public class StorageObject extends BaseStorageItem implements Cloneable
Modifier and Type | Field and Description |
---|---|
protected AccessControlList |
acl |
protected String |
bucketName |
protected 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 InputStream |
dataInputStream |
protected boolean |
isMetadataComplete |
static String |
METADATA_HEADER_HASH_MD5 |
static String |
METADATA_HEADER_ORIGINAL_HASH_MD5 |
static String |
METADATA_HEADER_SERVER_SIDE_ENCRYPTION |
protected String |
serverSideEncryptionAlgorithm |
protected 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(File file)
Create an object representing a file.
|
StorageObject(String key)
Create an object without any associated data.
|
StorageObject(String key,
byte[] data)
Create an object representing binary data.
|
StorageObject(String key,
String dataString)
Create an object representing text data.
|
Modifier and Type | Method and Description |
---|---|
void |
addAllMetadata(Map<String,Object> metadata)
Add all the metadata information to the object from the provided map.
|
void |
addMetadata(String name,
String value)
Add metadata information to the object.
|
Object |
clone() |
void |
closeDataInputStream()
Closes the object's data input stream if it exists.
|
AccessControlList |
getAcl() |
String |
getBucketName() |
String |
getContentDisposition() |
String |
getContentEncoding() |
String |
getContentLanguage() |
long |
getContentLength() |
String |
getContentType() |
File |
getDataInputFile() |
InputStream |
getDataInputStream()
Returns an input stream containing this object's data, or null if there is
no data associated with the object.
|
String |
getETag() |
String |
getKey() |
Date |
getLastModifiedDate() |
String |
getMd5HashAsBase64() |
String |
getMd5HashAsHex() |
Map<String,Object> |
getModifiableMetadata()
Returns only those object metadata items that can be modified in
a service.
|
String |
getServerSideEncryptionAlgorithm() |
String |
getStorageClass() |
boolean |
isDirectoryPlaceholder() |
boolean |
isMetadataComplete() |
void |
setAcl(AccessControlList acl)
Set the object's ACL.
|
void |
setBucketName(String bucketName)
Set the name of the bucket this object belongs to or will be placed into.
|
void |
setContentDisposition(String contentDisposition)
Set the content disposition of the object.
|
void |
setContentEncoding(String contentEncoding)
Set the content encoding of this object.
|
void |
setContentLanguage(String contentLanguage)
Set the content language of the object.
|
void |
setContentLength(long size)
Set this object's content length.
|
void |
setContentType(String contentType)
Set the content type of the object.
|
void |
setDataInputFile(File dataInputFile)
Sets the file containing the data content to associate with this object.
|
void |
setDataInputStream(InputStream dataInputStream)
Sets an input stream containing the data content to associate with this object.
|
void |
setETag(String etag)
Set the ETag value of the object based on information returned from the service.
|
void |
setKey(String key)
Set the key of this object.
|
void |
setLastModifiedDate(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(String serverSideEncryptionAlgorithm)
Set the encryption algorithm to use for server-side encryption of this object
(will be unencrypted if set to null)
|
void |
setStorageClass(String storageClass)
Set the storage class for this object.
|
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(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(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, getMetadata, getMetadataMap, getName, getOwner, getServiceMetadataMap, getUserMetadataMap, isMatchingMetadataName, lookupMetadataSubsetMap, removeMetadata, replaceAllMetadata, setName, setOwner
public static final String METADATA_HEADER_HASH_MD5
public static final String METADATA_HEADER_ORIGINAL_HASH_MD5
public static final String METADATA_HEADER_SERVER_SIDE_ENCRYPTION
protected AccessControlList acl
protected transient InputStream dataInputStream
protected boolean isMetadataComplete
protected String bucketName
protected String storageClass
protected String serverSideEncryptionAlgorithm
protected File dataInputFile
public StorageObject(File file) throws NoSuchAlgorithmException, 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.IOException
- when an i/o error occurred reading the fileNoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(String key, String dataString) throws NoSuchAlgorithmException, 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.IOException
NoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(String key, byte[] data) throws NoSuchAlgorithmException, 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.IOException
NoSuchAlgorithmException
- when this JRE doesn't support the MD5 hash algorithmpublic StorageObject(String key)
key
- the key name for the object.public StorageObject()
public String getBucketName()
public void setBucketName(String bucketName)
bucketName
- the name for the bucket.public 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(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(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 File getDataInputFile()
public void closeDataInputStream() throws IOException
IOException
public String getETag()
public void setETag(String etag)
etag
- the ETag value as provided by the service.public String getMd5HashAsHex()
md5-hash
, or null if the hash value is not available.public 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 Date getLastModifiedDate()
public void setLastModifiedDate(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 String getContentType()
public void setContentType(String contentType)
Mimetypes
).
You should set the content type for associated String or InputStream data.contentType
- public String getContentLanguage()
public void setContentLanguage(String contentLanguage)
contentLanguage
- public String getContentDisposition()
public void setContentDisposition(String contentDisposition)
contentDisposition
- public String getContentEncoding()
public void setContentEncoding(String contentEncoding)
contentEncoding
- public String getKey()
public void setKey(String key)
key
- the key for this object.public AccessControlList getAcl()
public void setAcl(AccessControlList acl)
acl
- public String getStorageClass()
public void setStorageClass(String storageClass)
storageClass
- public String getServerSideEncryptionAlgorithm()
public void setServerSideEncryptionAlgorithm(String serverSideEncryptionAlgorithm)
serverSideEncryptionAlgorithm
- public boolean isMetadataComplete()
public void setMetadataComplete(boolean isMetadataComplete)
isMetadataComplete
- public void addMetadata(String name, String value)
addMetadata
in class BaseStorageItem
name
- value
- public void addAllMetadata(Map<String,Object> metadata)
addAllMetadata
in class BaseStorageItem
metadata
- public Map<String,Object> getModifiableMetadata()
public boolean isDirectoryPlaceholder()
public boolean verifyData(File downloadedFile) throws NoSuchAlgorithmException, FileNotFoundException, IOException
downloadedFile
- 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).NoSuchAlgorithmException
FileNotFoundException
IOException
public boolean verifyData(byte[] downloadedData) throws NoSuchAlgorithmException, FileNotFoundException, IOException
downloadedData
- NoSuchAlgorithmException
FileNotFoundException
IOException
public boolean verifyData(InputStream downloadedDataStream) throws NoSuchAlgorithmException, FileNotFoundException, IOException
downloadedDataStream
- the input stream of a downloaded object.NoSuchAlgorithmException
FileNotFoundException
IOException
Copyright © 2006–2018. All rights reserved.