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

The following are Jave code examples for showing how to use listObjects() 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 7 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());
}
 
Example 2
Project: circus-train   File: TestUtils.java   View Source Code Vote up 5 votes
public static List<S3ObjectSummary> listObjects(AmazonS3 client, String bucket) {
  ObjectListing objects = client.listObjects(bucket);
  List<S3ObjectSummary> result = new ArrayList<>(objects.getObjectSummaries().size());
  for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
    if (objectSummary.getKey().endsWith("/") || objectSummary.getKey().endsWith("_$folder$")) {
      continue;
    }
    result.add(objectSummary);
  }
  return result;
}