Package org.jets3t.service.utils
Class ObjectUtils
java.lang.Object
org.jets3t.service.utils.ObjectUtils
Utility class for preparing files for upload into S3, or for download from
S3. The methods in this class build the appropriate objects to wrap uploaded
files or objects in S3 that will be downloaded to a local file.
- Author:
- James Murty
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertDirPlaceholderKeyNameToDirName
(String objectKey) static S3Object
createObjectForUpload
(String objectKey, File dataFile, EncryptionUtil encryptionUtil, boolean gzipFile) Prepares a file for upload to a named object in S3, potentially transforming it if zipping or encryption is requested.static S3Object
createObjectForUpload
(String objectKey, File dataFile, EncryptionUtil encryptionUtil, boolean gzipFile, BytesProgressWatcher progressWatcher) Prepares a file for upload to a named object in S3, potentially transforming it if zipping or encryption is requested.static DownloadPackage
createPackageForDownload
(S3Object object, File fileTarget, boolean automaticUnzip, boolean automaticDecrypt, String encryptionPassword) Deprecated.static DownloadPackage
createPackageForDownload
(StorageObject object, File fileTarget, boolean automaticUnzip, boolean automaticDecrypt, String encryptionPassword) Creates a download package representing an S3Object that will be downloaded, and the target file the downloaded data will be written to.
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
createObjectForUpload
public static S3Object createObjectForUpload(String objectKey, File dataFile, EncryptionUtil encryptionUtil, boolean gzipFile, BytesProgressWatcher progressWatcher) throws Exception Prepares a file for upload to a named object in S3, potentially transforming it if zipping or encryption is requested.The file will have the following metadata items added:
Constants.METADATA_JETS3T_LOCAL_FILE_DATE
: The local file's last modified date in ISO 8601 format- Content-Type : A content type guessed from the file's extension, or
Mimetypes.MIMETYPE_BINARY_OCTET_STREAM
if the file is a directory - Content-Length : The size of the file
- MD5-Hash : An MD5 hash of the file's data
StorageObject.METADATA_HEADER_ORIGINAL_HASH_MD5
: An MD5 hash of the original file's data (added if gzipping or encryption is applied)
- Parameters:
objectKey
- the object key name to use in S3dataFile
- the file to prepare for upload.encryptionUtil
- if this variable is null no encryption will be applied, otherwise the provided encryption utility object will be used to encrypt the file's data.gzipFile
- if true the file will be Gzipped.progressWatcher
- watcher to monitor progress of file transformation and hash generation.- Returns:
- an S3Object representing the file, or a transformed copy of the file, complete with all JetS3t-specific metadata items set and ready for upload to S3.
- Throws:
Exception
- exceptions could include IO failures, gzipping and encryption failures.
-
createObjectForUpload
public static S3Object createObjectForUpload(String objectKey, File dataFile, EncryptionUtil encryptionUtil, boolean gzipFile) throws Exception Prepares a file for upload to a named object in S3, potentially transforming it if zipping or encryption is requested.The file will have the following metadata items added:
Constants.METADATA_JETS3T_LOCAL_FILE_DATE
: The local file's last modified date in ISO 8601 format- Content-Type : A content type guessed from the file's extension, or
Mimetypes.MIMETYPE_BINARY_OCTET_STREAM
if the file is a directory - Content-Length : The size of the file
- MD5-Hash : An MD5 hash of the file's data
StorageObject.METADATA_HEADER_ORIGINAL_HASH_MD5
: An MD5 hash of the original file's data (added if gzipping or encryption is applied)
- Parameters:
objectKey
- the object key name to use in S3dataFile
- the file to prepare for upload.encryptionUtil
- if this variable is null no encryption will be applied, otherwise the provided encryption utility object will be used to encrypt the file's data.gzipFile
- if true the file will be Gzipped.- Returns:
- an S3Object representing the file, or a transformed copy of the file, complete with all JetS3t-specific metadata items set and ready for upload to S3.
- Throws:
Exception
- exceptions could include IO failures, gzipping and encryption failures.
-
createPackageForDownload
public static DownloadPackage createPackageForDownload(StorageObject object, File fileTarget, boolean automaticUnzip, boolean automaticDecrypt, String encryptionPassword) throws Exception Creates a download package representing an S3Object that will be downloaded, and the target file the downloaded data will be written to.Downloaded data may be transformed if the S3Object is encrypted or gzipped and the appropriate options are set.
- Parameters:
object
- the objectfileTarget
- the file to which downloaded (and possibly transformed) data will be written.automaticUnzip
- if true, gzipped objects will be decrypted on-the-fly as they are downloaded.automaticDecrypt
- if true, encrypted files will be decrypted on-the-fly as they are downloaded (in which case the encryptionPassword must be correct)encryptionPassword
- the password required to decrypt encrypted objects.- Returns:
- a download package representing an S3Object and a taret file for the object's data.
- Throws:
Exception
-
createPackageForDownload
@Deprecated public static DownloadPackage createPackageForDownload(S3Object object, File fileTarget, boolean automaticUnzip, boolean automaticDecrypt, String encryptionPassword) throws Exception Deprecated.0.8.0 usecreatePackageForDownload(StorageObject, File, boolean, boolean, String)
instead.Creates a download package representing an S3Object that will be downloaded, and the target file the downloaded data will be written to.Downloaded data may be transformed if the S3Object is encrypted or gzipped and the appropriate options are set.
- Parameters:
object
- the objectfileTarget
- the file to which downloaded (and possibly transformed) data will be written.automaticUnzip
- if true, gzipped objects will be decrypted on-the-fly as they are downloaded.automaticDecrypt
- if true, encrypted files will be decrypted on-the-fly as they are downloaded (in which case the encryptionPassword must be correct)encryptionPassword
- the password required to decrypt encrypted objects.- Returns:
- a download package representing an S3Object and a taret file for the object's data.
- Throws:
Exception
-
convertDirPlaceholderKeyNameToDirName
-
createPackageForDownload(StorageObject, File, boolean, boolean, String)
instead.