if (fileTarget.getParentFile() != null) {
fileTarget.getParentFile().mkdirs();
}
boolean isZipped = false;
EncryptionUtil encryptionUtil = null;
if (automaticUnzip &&
("gzip".equalsIgnoreCase(object.getContentEncoding())
|| object.containsMetadata(Constants.METADATA_JETS3T_COMPRESSED)))
{
// Object data is gzipped.
isZipped = true;
}
if (automaticDecrypt
&& (object.containsMetadata(Constants.METADATA_JETS3T_ENCRYPTED_OBSOLETE)
|| object.containsMetadata(Constants.METADATA_JETS3T_CRYPTO_ALGORITHM)))
{
// Object is encrypted.
if (encryptionPassword == null) {
throw new S3ServiceException(
"One or more objects are encrypted, and cannot be downloaded unless "
+ " the encyption password is provided");
}
if (object.containsMetadata(Constants.METADATA_JETS3T_ENCRYPTED_OBSOLETE)) {
// Item is encrypted with obsolete crypto.
encryptionUtil = EncryptionUtil.getObsoleteEncryptionUtil(
encryptionPassword);
} else {
String algorithm = (String) object.getMetadata(
Constants.METADATA_JETS3T_CRYPTO_ALGORITHM);
String version = (String) object.getMetadata(
Constants.METADATA_JETS3T_CRYPTO_VERSION);
if (version == null) {
version = EncryptionUtil.DEFAULT_VERSION;
}
encryptionUtil = new EncryptionUtil(encryptionPassword, algorithm, version);
}
}
return new DownloadPackage(object, fileTarget, isZipped, encryptionUtil);
}