I am using the following code snippet for listing objects in a bucket.
objectListing = client.listObjects(bucketname); do{ for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.printf(" - %s (size: %d)\n", objectSummary.getKey(), objectSummary.getSize()); } objectListing=s3Client.listNextBatchOfObjects(objectListing); }while (objectListing.isTruncated()); I am not able to get the last batch of objects.I did some research regarding this and the batches are being saved in list.But I am not able to use list to save all the objects as there are million of objects and this will cause the heap memory problem sometimes.How can i get all the objects.Thanks!!!
New:
I am running this:
BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar"); client = AmazonS3ClientBuilder .standard() .withCredentials(new AWSStaticCredentialsProvider(credentials)) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:" + port, null)) .withPathStyleAccessEnabled(true) .withChunkedEncodingDisabled(true) .build(); ObjectListing listing = client.listObjects( "bucketname"); System.out.println("Listing size "+listing.getObjectSummaries().size()); System.out.println("At 0 index "+ listing.getObjectSummaries().get(0).getKey()); System.out.println("At 999 index "+ listing.getObjectSummaries().get(999).getKey()); while (listing.isTruncated()) { System.out.println("-----------------------------------------------"); listing = client.listNextBatchOfObjects(listing); System.out.println("Listing size "+listing.getObjectSummaries().size()); System.out.println("At 0 index "+ listing.getObjectSummaries().get(0).getKey()); System.out.println("At 999 index "+ listing.getObjectSummaries().get(1000).getKey()); } I am getting following result:
Listing size 1000 At 0 index folder1/a.gz At 999 index folder1/b.gz --------------------------------------------------------------- Listing size 1001 At 0 index folder1/b.gz At 1000 index folder1/d.gz --------------------------------------------------------------- Listing size 1001 At 0 index folder1/d.gz At 1000 index folder1/e.gz