use of com.amazonaws.services.s3.transfer.internal.DownloadImpl in project herd by FINRAOS.
the class MockS3OperationsImpl method download.
@Override
public Download download(String bucket, String key, File file, TransferManager transferManager) {
MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucket);
MockS3Object mockS3Object = mockS3Bucket.getObjects().get(key);
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
fileOutputStream.write(mockS3Object.getData());
} catch (IOException e) {
throw new RuntimeException("Error writing to file " + file, e);
}
TransferProgress progress = new TransferProgress();
progress.setTotalBytesToTransfer(mockS3Object.getData().length);
progress.updateProgress(mockS3Object.getData().length);
DownloadImpl download = new DownloadImpl(null, progress, null, null, null, new GetObjectRequest(bucket, key), file, mockS3Object.getObjectMetadata(), false);
download.setState(TransferState.Completed);
return download;
}
use of com.amazonaws.services.s3.transfer.internal.DownloadImpl in project herd by FINRAOS.
the class MockS3OperationsImpl method downloadDirectory.
/**
* {@inheritDoc}
* <p/>
* This implementation creates any directory that does not exist in the path to the destination directory.
*/
@Override
public MultipleFileDownload downloadDirectory(String bucketName, String keyPrefix, File destinationDirectory, TransferManager transferManager) {
LOGGER.debug("downloadDirectory(): bucketName = " + bucketName + ", keyPrefix = " + keyPrefix + ", destinationDirectory = " + destinationDirectory);
MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
List<Download> downloads = new ArrayList<>();
long totalBytes = 0;
if (mockS3Bucket != null) {
for (MockS3Object mockS3Object : mockS3Bucket.getObjects().values()) {
if (mockS3Object.getKey().startsWith(keyPrefix)) {
String filePath = destinationDirectory.getAbsolutePath() + "/" + mockS3Object.getKey();
File file = new File(filePath);
// Create any directory in the path that does not exist.
file.getParentFile().mkdirs();
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
LOGGER.debug("downloadDirectory(): Writing file " + file);
fileOutputStream.write(mockS3Object.getData());
totalBytes += mockS3Object.getData().length;
downloads.add(new DownloadImpl(null, null, null, null, null, new GetObjectRequest(bucketName, mockS3Object.getKey()), file, mockS3Object.getObjectMetadata(), false));
} catch (IOException e) {
throw new RuntimeException("Error writing to file " + file, e);
}
}
}
}
TransferProgress progress = new TransferProgress();
progress.setTotalBytesToTransfer(totalBytes);
progress.updateProgress(totalBytes);
MultipleFileDownloadImpl multipleFileDownload = new MultipleFileDownloadImpl(null, progress, null, keyPrefix, bucketName, downloads);
multipleFileDownload.setState(TransferState.Completed);
return multipleFileDownload;
}
Aggregations