private UploadResult uploadInSinglePart(final String accountId,
final String vaultName, final String archiveDescription,
final File file, ProgressListener progressListener) {
String checksum = TreeHashGenerator.calculateTreeHash(file);
ResettableInputStream is = newResettableInputStream(file);
try {
publishProgress(progressListener, ProgressEventType.TRANSFER_STARTED_EVENT);
final UploadArchiveRequest req = new UploadArchiveRequest()
.withAccountId(accountId)
.withArchiveDescription(archiveDescription)
.withVaultName(vaultName)
.withChecksum(checksum)
.withBody(is)
.withContentLength(file.length())
// capture the bytes transferred
.withGeneralProgressListener(progressListener)
;
UploadArchiveResult uploadArchiveResult = glacier.uploadArchive(req);
String artifactId = uploadArchiveResult.getArchiveId();
publishProgress(progressListener, ProgressEventType.TRANSFER_COMPLETED_EVENT);
return new UploadResult(artifactId);
} catch (Throwable t) {
publishProgress(progressListener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw failure(t);
} finally {
is.release();
}
}