@Override public void downloadBackup( Exhibitor exhibitor, BackupMetaData backup, File destination, Map<String, String> configValues) throws Exception { S3Object object = s3Client.getObject(configValues.get(CONFIG_BUCKET.getKey()), toKey(backup)); long startMs = System.currentTimeMillis(); RetryPolicy retryPolicy = makeRetryPolicy(configValues); int retryCount = 0; boolean done = false; while (!done) { Throttle throttle = makeThrottle(configValues); InputStream in = null; FileOutputStream out = null; try { out = new FileOutputStream(destination); in = object.getObjectContent(); FileChannel channel = out.getChannel(); CompressorIterator compressorIterator = compressor.decompress(in); for (; ; ) { ByteBuffer bytes = compressorIterator.next(); if (bytes == null) { break; } throttle.throttle(bytes.limit()); channel.write(bytes); } done = true; } catch (Exception e) { if (!retryPolicy.allowRetry(retryCount++, System.currentTimeMillis() - startMs)) { done = true; } } finally { Closeables.closeQuietly(in); Closeables.closeQuietly(out); } } }