List of usage examples for com.amazonaws.services.s3.model ListVersionsRequest setVersionIdMarker
public void setVersionIdMarker(String versionIdMarker)
versionIdMarker parameter indicating where in the sorted list of all versions in the specified bucket to begin returning results. From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public List<S3VersionSummary> listVersions(final S3FileTransferRequestParamsDto params) { Assert.isTrue(!isRootKeyPrefix(params.getS3KeyPrefix()), "Listing of S3 versions from root directory is not allowed."); AmazonS3Client s3Client = getAmazonS3(params); List<S3VersionSummary> s3VersionSummaries = new ArrayList<>(); try {/*from w w w . j ava2s . c o m*/ ListVersionsRequest listVersionsRequest = new ListVersionsRequest() .withBucketName(params.getS3BucketName()).withPrefix(params.getS3KeyPrefix()); VersionListing versionListing; do { versionListing = s3Operations.listVersions(listVersionsRequest, s3Client); s3VersionSummaries.addAll(versionListing.getVersionSummaries()); listVersionsRequest.setKeyMarker(versionListing.getNextKeyMarker()); listVersionsRequest.setVersionIdMarker(versionListing.getNextVersionIdMarker()); } while (versionListing.isTruncated()); } catch (AmazonS3Exception amazonS3Exception) { if (S3Operations.ERROR_CODE_NO_SUCH_BUCKET.equals(amazonS3Exception.getErrorCode())) { throw new IllegalArgumentException( "The specified bucket '" + params.getS3BucketName() + "' does not exist.", amazonS3Exception); } throw new IllegalStateException("Error accessing S3", amazonS3Exception); } catch (AmazonClientException e) { throw new IllegalStateException( String.format("Failed to list S3 versions with prefix \"%s\" from bucket \"%s\". Reason: %s", params.getS3KeyPrefix(), params.getS3BucketName(), e.getMessage()), e); } finally { // Shutdown the AmazonS3Client instance to release resources. s3Client.shutdown(); } return s3VersionSummaries; }