*/
private void downloadOneChunk(String accountId, String vaultName,
String jobId, RandomAccessFile output, long currentPosition,
long endPosition, ProgressListener progressListener) {
final long chunkSize = endPosition - currentPosition + 1;
TreeHashInputStream input = null;
int retries = 0;
while (true) {
try {
GetJobOutputRequest req = new GetJobOutputRequest()
.withAccountId(accountId)
.withVaultName(vaultName)
.withRange("bytes=" + currentPosition + "-" + endPosition)
.withJobId(jobId)
.withGeneralProgressListener(progressListener)
;
GetJobOutputResult jobOutputResult = glacier.getJobOutput(req);
try {
input = new TreeHashInputStream(new BufferedInputStream(jobOutputResult.getBody()));
appendToFile(output, input);
} catch (NoSuchAlgorithmException e) {
throw failure(e, "Unable to compute hash for data integrity");
} finally {
closeQuietly(input, log);
}
// Only do tree-hash check when the output checksum is returned from Glacier
if (null != jobOutputResult.getChecksum()) {
// Checksum does not match
if (!input.getTreeHash().equalsIgnoreCase(jobOutputResult.getChecksum())) {
// Discard the chunk of bytes received
publishResponseBytesDiscarded(progressListener, chunkSize);
if (log.isDebugEnabled())
log.debug("reverting " + chunkSize);
throw new IOException("Client side computed hash doesn't match server side hash; possible data corruption");