Example usage for com.amazonaws.services.s3 AmazonS3 listVersions

List of usage examples for com.amazonaws.services.s3 AmazonS3 listVersions

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3 listVersions.

Prototype

public VersionListing listVersions(String bucketName, String prefix, String keyMarker, String versionIdMarker,
        String delimiter, Integer maxResults) throws SdkClientException, AmazonServiceException;

Source Link

Document

Returns a list of summary information about the versions in the specified bucket.

Usage

From source file:com.emc.ecs.sync.util.AwsS3Util.java

License:Open Source License

public static ListIterator<S3ObjectVersion> listVersions(SyncPlugin parentPlugin, AmazonS3 s3, String bucket,
        String key, String relativePath) {
    List<S3ObjectVersion> versions = new ArrayList<>();

    VersionListing listing = null;//  w w w .j  a  va  2 s  . c o m
    do {
        if (listing == null)
            listing = s3.listVersions(bucket, key, null, null, "/", null);
        else
            listing = s3.listNextBatchOfVersions(listing);

        for (S3VersionSummary summary : listing.getVersionSummaries()) {

            if (summary.getKey().equals(key)) {
                versions.add(new S3ObjectVersion(parentPlugin, s3, bucket, key, summary.getVersionId(),
                        summary.isLatest(), summary.isDeleteMarker(), summary.getLastModified(),
                        summary.getETag(), relativePath, summary.getSize()));
            }
        }
    } while (listing.isTruncated());

    // sort chronologically
    Collections.sort(versions, new VersionComparator());
    return versions.listIterator();
}