}
String actionText = "";
// Create a temporary file to hold data transformed from the original file.
final File tempUploadFile = new TempFile(File.createTempFile("JetS3t",".tmp"));
tempUploadFile.deleteOnExit();
// Transform data from original file, gzipping or encrypting as specified in user's options.
OutputStream outputStream = null;
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(dataFile));
outputStream = new BufferedOutputStream(new FileOutputStream(tempUploadFile));
String contentEncoding = null;
if (gzipFile) {
inputStream = new GZipDeflatingInputStream(inputStream);
contentEncoding = "gzip";
s3Object.addMetadata(Constants.METADATA_JETS3T_COMPRESSED, "gzip");
actionText += "Compressing";
}
if (encryptionUtil != null) {
inputStream = encryptionUtil.encrypt(inputStream);
contentEncoding = null;
s3Object.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
s3Object.addMetadata(Constants.METADATA_JETS3T_CRYPTO_ALGORITHM,
encryptionUtil.getAlgorithm());
s3Object.addMetadata(Constants.METADATA_JETS3T_CRYPTO_VERSION,
EncryptionUtil.DEFAULT_VERSION);
actionText += (actionText.length() == 0? "Encrypting" : " and encrypting");
}
if (contentEncoding != null) {
s3Object.addMetadata("Content-Encoding", contentEncoding);
}
if (log.isDebugEnabled()) {
log.debug("Transforming upload file '" + dataFile + "' to temporary file '"
+ tempUploadFile.getAbsolutePath() + "': " + actionText);
}
if (progressWatcher != null) {
inputStream = new ProgressMonitoredInputStream(inputStream, progressWatcher);
}