Java Code Examples for com.amazonaws.services.s3.AmazonS3.listNextBatchOfObjects()

The following are Jave code examples for showing how to use listNextBatchOfObjects() of the com.amazonaws.services.s3.AmazonS3 class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ooso   File: Commons.java   View Source Code Vote up 8 votes
public static List<S3ObjectSummary> getBucketObjectSummaries(String bucket, String prefix) {
    String realBucket = getBucketFromFullPath(bucket);
    String preprefix = getPrefixFromFullPath(bucket);

    AmazonS3 s3Client = AmazonS3Provider.getS3Client();
    ListObjectsRequest req = new ListObjectsRequest().withBucketName(realBucket).withPrefix(!preprefix.equals("") ? preprefix + "/" + prefix : prefix);
    ObjectListing objectListing = s3Client.listObjects(req);
    List<S3ObjectSummary> summaries = objectListing.getObjectSummaries();

    while (objectListing.isTruncated()) {
        objectListing = s3Client.listNextBatchOfObjects(objectListing);
        summaries.addAll(objectListing.getObjectSummaries());
    }

    return summaries.stream().filter(obj -> !obj.getKey().equals("") && !obj.getKey().endsWith("/")).collect(toList());
}