download.setS3Object(s3Object);
if (s3Object == null) {
download.setState(TransferState.Canceled);
download.setMonitor(new DownloadMonitor(download, null));
return download;
}
// Don't perform the integrity check if the stream data is wrapped
// in a decryption stream, or if we're only looking at a range of
// the data, since otherwise the checksum won't match up.
boolean performIntegrityCheck = true;
if (getObjectRequest.getRange() != null) performIntegrityCheck = false;
if (s3 instanceof AmazonS3EncryptionClient) performIntegrityCheck = false;
ServiceUtils.downloadObjectToFile(s3Object, file, performIntegrityCheck);
download.setState(TransferState.Completed);
return true;
} catch (Exception e) {
// Downloads aren't allowed to move from canceled to failed
if (download.getState() != TransferState.Canceled) {
download.setState(TransferState.Failed);
}
throw e;
}
}
});
download.setMonitor(new DownloadMonitor(download, future));
synchronized (startDownloadLock) {
startDownloadLock.downloadReady = true;
startDownloadLock.notify();
}
return download;