transferProgress, additionalProgressListenerChain);
List<DownloadImpl> downloads = new ArrayList<DownloadImpl>();
String description = "Downloading from " + bucketName + "/" + keyPrefix;
final MultipleFileDownloadImpl multipleFileDownload = new MultipleFileDownloadImpl(description, transferProgress,
additionalProgressListenerChain, keyPrefix, bucketName, downloads);
multipleFileDownload.setMonitor(new MultipleFileTransferMonitor(multipleFileDownload, downloads));
final AllDownloadsQueuedLock allTransfersQueuedLock = new AllDownloadsQueuedLock();
MultipleFileTransferStateChangeListener multipleFileTransferStateChangeListener = new MultipleFileTransferStateChangeListener(
allTransfersQueuedLock, multipleFileDownload);
for ( S3ObjectSummary summary : objectSummaries ) {
// TODO: non-standard delimiters
File f = new File(destinationDirectory, summary.getKey());
File parentFile = f.getParentFile();
if ( !parentFile.exists() && !parentFile.mkdirs() ) {
throw new RuntimeException("Couldn't create parent directories for " + f.getAbsolutePath());
}
// All the single-file downloads share the same
// MultipleFileTransferProgressUpdatingListener and
// MultipleFileTransferStateChangeListener
downloads.add((DownloadImpl) download(
new GetObjectRequest(summary.getBucketName(),
summary.getKey())
.withGeneralProgressListener(
multipleFileTransferProgressListener),
f,
multipleFileTransferStateChangeListener));
}
if ( downloads.isEmpty() ) {
multipleFileDownload.setState(TransferState.Completed);
return multipleFileDownload;
}
// Notify all state changes waiting for the downloads to all be queued
// to wake up and continue.