use of com.amazonaws.services.s3.transfer.Download in project deeplearning4j by deeplearning4j.
the class S3Downloader method download.
public void download(String bucket, String key, OutputStream to) throws IOException {
AmazonS3 s3 = getClient();
S3Object obj = s3.getObject(bucket, key);
InputStream is = obj.getObjectContent();
BufferedOutputStream bos = new BufferedOutputStream(to);
IOUtils.copy(is, bos);
bos.close();
is.close();
obj.close();
}
use of com.amazonaws.services.s3.transfer.Download in project deeplearning4j by deeplearning4j.
the class S3Downloader method download.
public void download(String bucket, String key, File to) throws IOException {
AmazonS3 s3 = getClient();
S3Object obj = s3.getObject(bucket, key);
InputStream is = obj.getObjectContent();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(to));
IOUtils.copy(is, bos);
bos.close();
is.close();
obj.close();
}
use of com.amazonaws.services.s3.transfer.Download in project YCSB by brianfrankcooper.
the class S3Client method readFromStorage.
/**
* Download an object from S3.
*
* @param bucket
* The name of the bucket
* @param key
* The file key of the object to upload/update.
* @param result
* The Hash map where data from the object are written
*
*/
protected Status readFromStorage(String bucket, String key, HashMap<String, ByteIterator> result, SSECustomerKey ssecLocal) {
try {
Map.Entry<S3Object, ObjectMetadata> objectAndMetadata = getS3ObjectAndMetadata(bucket, key, ssecLocal);
//consuming the stream
InputStream objectData = objectAndMetadata.getKey().getObjectContent();
// writing the stream to bytes and to results
int sizeOfFile = (int) objectAndMetadata.getValue().getContentLength();
byte[] inputStreamToByte = new byte[sizeOfFile];
objectData.read(inputStreamToByte, 0, sizeOfFile);
result.put(key, new ByteArrayByteIterator(inputStreamToByte));
objectData.close();
objectAndMetadata.getKey().close();
} catch (Exception e) {
System.err.println("Not possible to get the object " + key);
e.printStackTrace();
return Status.ERROR;
}
return Status.OK;
}
use of com.amazonaws.services.s3.transfer.Download in project incubator-gobblin by apache.
the class AWSSdkClient method downloadS3Object.
/**
* Download a S3 object to local directory
*
* @param s3ObjectSummary S3 object summary for the object to download
* @param targetDirectory Local target directory to download the object to
* @throws IOException If any errors were encountered in downloading the object
*/
public void downloadS3Object(S3ObjectSummary s3ObjectSummary, String targetDirectory) throws IOException {
final AmazonS3 amazonS3 = getS3Client();
final GetObjectRequest getObjectRequest = new GetObjectRequest(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey());
final S3Object s3Object = amazonS3.getObject(getObjectRequest);
final String targetFile = StringUtils.removeEnd(targetDirectory, File.separator) + File.separator + s3Object.getKey();
FileUtils.copyInputStreamToFile(s3Object.getObjectContent(), new File(targetFile));
LOGGER.info("S3 object downloaded to file: " + targetFile);
}
use of com.amazonaws.services.s3.transfer.Download 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;
}
Aggregations