com.amazonaws.services.s3.iterable
Class S3Objects

java.lang.Object
  extended by com.amazonaws.services.s3.iterable.S3Objects
All Implemented Interfaces:
Iterable<S3ObjectSummary>

public class S3Objects
extends Object
implements Iterable<S3ObjectSummary>

Provides an easy way to iterate Amazon S3 objects in a "foreach" statement. For example:

 for ( S3ObjectSummary summary : S3Objects.withPrefix(s3, "my-bucket", "photos/") ) {
     System.out.printf("Object with key '%s'\n", summary.getKey());
 }
 

The list of S3ObjectSummarys will be fetched lazily, a page at a time, as they are needed. The size of the page can be controlled with the withBatchSize(int) method.


Method Summary
 Integer getBatchSize()
           
 String getBucketName()
           
 String getPrefix()
           
 AmazonS3 getS3()
           
static S3Objects inBucket(AmazonS3 s3, String bucketName)
          Constructs an iterable that covers all the objects in an Amazon S3 bucket.
 Iterator<S3ObjectSummary> iterator()
           
 S3Objects withBatchSize(int batchSize)
          Sets the batch size, i.e., how many S3ObjectSummarys will be fetched at once.
static S3Objects withPrefix(AmazonS3 s3, String bucketName, String prefix)
          Constructs an iterable that covers the objects in an Amazon S3 bucket where the key begins with the given prefix.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

inBucket

public static S3Objects inBucket(AmazonS3 s3,
                                 String bucketName)
Constructs an iterable that covers all the objects in an Amazon S3 bucket.

Parameters:
s3 - The Amazon S3 client.
bucketName - The bucket name.
Returns:
An iterator for object summaries.

withPrefix

public static S3Objects withPrefix(AmazonS3 s3,
                                   String bucketName,
                                   String prefix)
Constructs an iterable that covers the objects in an Amazon S3 bucket where the key begins with the given prefix.

Parameters:
s3 - The Amazon S3 client.
bucketName - The bucket name.
prefix - The prefix.
Returns:
An iterator for object summaries.

withBatchSize

public S3Objects withBatchSize(int batchSize)
Sets the batch size, i.e., how many S3ObjectSummarys will be fetched at once.

Parameters:
batchSize - How many object summaries to fetch at once.

getBatchSize

public Integer getBatchSize()

getPrefix

public String getPrefix()

getBucketName

public String getBucketName()

getS3

public AmazonS3 getS3()

iterator

public Iterator<S3ObjectSummary> iterator()
Specified by:
iterator in interface Iterable<S3ObjectSummary>


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.