Example usage for com.amazonaws.services.s3.model ListObjectsRequest withMaxKeys

List of usage examples for com.amazonaws.services.s3.model ListObjectsRequest withMaxKeys

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ListObjectsRequest withMaxKeys.

Prototype

public ListObjectsRequest withMaxKeys(Integer maxKeys) 

Source Link

Document

Sets the optional maxKeys parameter indicating the maximum number of keys to include in the response.

Usage

From source file:org.springframework.integration.aws.s3.core.AmazonS3OperationsImpl.java

License:Apache License

public PaginatedObjectsView listObjects(String bucketName, String folder, String nextMarker, int pageSize) {
    if (logger.isDebugEnabled()) {
        logger.debug("Listing objects from bucket " + bucketName + " and folder " + folder);
        logger.debug("Next marker is " + nextMarker + " and pageSize is " + pageSize);
    }/*from   w  w  w  . jav a  2  s . c o m*/

    Assert.notNull(StringUtils.hasText(bucketName), "Bucket name should be non null and non empty");
    String prefix = null;
    if (folder != null && !"/".equals(folder)) {
        prefix = folder;
    }
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
            .withPrefix(prefix).withMarker(nextMarker);

    if (pageSize > 0) {
        listObjectsRequest.withMaxKeys(pageSize);
    }

    ObjectListing listing = client.listObjects(listObjectsRequest);
    PaginatedObjectsView view = null;
    List<com.amazonaws.services.s3.model.S3ObjectSummary> summaries = listing.getObjectSummaries();
    if (summaries != null && !summaries.isEmpty()) {
        List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>();
        for (final com.amazonaws.services.s3.model.S3ObjectSummary summary : summaries) {
            S3ObjectSummary summ = new S3ObjectSummary() {

                public long getSize() {
                    return summary.getSize();
                }

                public Date getLastModified() {
                    return summary.getLastModified();
                }

                public String getKey() {
                    return summary.getKey();
                }

                public String getETag() {
                    return summary.getETag();
                }

                public String getBucketName() {
                    return summary.getBucketName();
                }
            };
            objectSummaries.add(summ);
        }
        view = new PagninatedObjectsViewImpl(objectSummaries, listing.getNextMarker());
    }
    return view;
}

From source file:org.springframework.integration.aws.s3.core.DefaultAmazonS3Operations.java

License:Apache License

/**
 * The implementation that uses the AWS SDK to list objects from the given bucket
 *
 * @param bucketName The bucket in which we want to list the objects in
 * @param nextMarker The number of objects can be very large and this serves as the marker
 *                 for remembering the last record fetch in the last retrieve operation.
 * @param pageSize The max number of records to be retrieved in one list object operation.
 * @param prefix The prefix for the list operation, this can serve as the folder whose contents
 *              are to be listed./*from ww w  .  ja v  a2  s.c  o  m*/
 */
@Override
protected PaginatedObjectsView doListObjects(String bucketName, String nextMarker, int pageSize,
        String prefix) {

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
            .withPrefix(prefix).withMarker(nextMarker);

    if (pageSize > 0) {
        listObjectsRequest.withMaxKeys(pageSize);
    }

    ObjectListing listing = client.listObjects(listObjectsRequest);
    PaginatedObjectsView view = null;
    List<com.amazonaws.services.s3.model.S3ObjectSummary> summaries = listing.getObjectSummaries();
    if (summaries != null && !summaries.isEmpty()) {
        List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>();
        for (final com.amazonaws.services.s3.model.S3ObjectSummary summary : summaries) {
            S3ObjectSummary summ = new S3ObjectSummary() {

                public long getSize() {
                    return summary.getSize();
                }

                public Date getLastModified() {
                    return summary.getLastModified();
                }

                public String getKey() {
                    return summary.getKey();
                }

                public String getETag() {
                    return summary.getETag();
                }

                public String getBucketName() {
                    return summary.getBucketName();
                }
            };
            objectSummaries.add(summ);
        }
        view = new PagninatedObjectsViewImpl(objectSummaries, listing.getNextMarker());
    }
    return view;
}