// Recurse all virtual subdirectories to get a list of object summaries.
// This is a depth-first search.
do {
String prefix = commonPrefixes.pop();
ObjectListing listObjectsResponse = null;
do {
if ( listObjectsResponse == null ) {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
.withDelimiter(DEFAULT_DELIMITER).withPrefix(prefix);
listObjectsResponse = s3.listObjects(listObjectsRequest);
} else {
listObjectsResponse = s3.listNextBatchOfObjects(listObjectsResponse);
}
for ( S3ObjectSummary s : listObjectsResponse.getObjectSummaries() ) {
// Skip any files that are also virtual directories, since
// we can't save both a directory and a file of the same
// name.
if ( !s.getKey().equals(prefix)
&& !listObjectsResponse.getCommonPrefixes().contains(s.getKey() + DEFAULT_DELIMITER) ) {
objectSummaries.add(s);
totalSize += s.getSize();
} else {
log.debug("Skipping download for object " + s.getKey()
+ " since it is also a virtual directory");
}
}
commonPrefixes.addAll(listObjectsResponse.getCommonPrefixes());
} while ( listObjectsResponse.isTruncated() );
} while ( !commonPrefixes.isEmpty() );
TransferProgressImpl transferProgress = new TransferProgressImpl();
transferProgress.setTotalBytesToTransfer(totalSize);
ProgressListener listener = new TransferProgressUpdatingListener(transferProgress);