List of usage examples for com.amazonaws.services.s3.transfer.internal DownloadImpl DownloadImpl
@Deprecated
public DownloadImpl(String description, TransferProgress transferProgress,
ProgressListenerChain progressListenerChain, S3Object s3Object, TransferStateChangeListener listener,
GetObjectRequest getObjectRequest, File file)
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * Downloads objects with the given prefix into a destination directory. * <p/>// ww w . jav a 2 s . c om * 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); file.getParentFile().mkdirs(); // Create any directory in the path that does not exist. 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)); } 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; }
From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java
License:Apache License
/** * Downloads an object.// www. j av a 2s . c o m */ @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); download.setState(TransferState.Completed); return download; }