private UploadResult uploadInSinglePart(final String accountId,
final String vaultName, final String archiveDescription,
final File file, ProgressListener progressListener)
throws AmazonServiceException, AmazonClientException, FileNotFoundException {
String checksum = TreeHashGenerator.calculateTreeHash(file);
InputStream is = new RepeatableFileInputStream(file);
publishProgress(progressListener, ProgressEventType.TRANSFER_STARTED_EVENT);
try {
UploadArchiveResult uploadArchiveResult =
glacier.uploadArchive(new UploadArchiveRequest()
.withAccountId(accountId)
.withArchiveDescription(archiveDescription)
.withVaultName(vaultName)
.withChecksum(checksum)
.withBody(is)
.withContentLength(file.length())
);
String artifactId = uploadArchiveResult.getArchiveId();
publishProgress(progressListener, ProgressEventType.TRANSFER_COMPLETED_EVENT);
return new UploadResult(artifactId);
} catch (AmazonClientException ace) {
publishProgress(progressListener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw ace;
} finally {
try {is.close();} catch (Exception e) {}
}
}