use of com.amazonaws.services.s3.model.S3VersionSummary in project aws-doc-sdk-examples by awsdocs.
the class ListKeysVersioningEnabledBucket method main.
public static void main(String[] args) {
Regions clientRegion = Regions.DEFAULT_REGION;
String bucketName = "*** Bucket name ***";
try {
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withCredentials(new ProfileCredentialsProvider()).withRegion(clientRegion).build();
// Retrieve the list of versions. If the bucket contains more versions
// than the specified maximum number of results, Amazon S3 returns
// one page of results per request.
ListVersionsRequest request = new ListVersionsRequest().withBucketName(bucketName).withMaxResults(2);
VersionListing versionListing = s3Client.listVersions(request);
int numVersions = 0, numPages = 0;
while (true) {
numPages++;
for (S3VersionSummary objectSummary : versionListing.getVersionSummaries()) {
System.out.printf("Retrieved object %s, version %s\n", objectSummary.getKey(), objectSummary.getVersionId());
numVersions++;
}
// there are, retrieve them. Otherwise, exit the loop.
if (versionListing.isTruncated()) {
versionListing = s3Client.listNextBatchOfVersions(versionListing);
} else {
break;
}
}
System.out.println(numVersions + " object versions retrieved in " + numPages + " pages");
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
Aggregations