Example usage for com.amazonaws.services.s3.model ObjectListing ObjectListing

List of usage examples for com.amazonaws.services.s3.model ObjectListing ObjectListing

Introduction

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

Prototype

ObjectListing

Source Link

Usage

From source file:com.netflix.exhibitor.core.backup.s3.MockS3Client.java

License:Apache License

@Override
public synchronized ObjectListing listObjects(ListObjectsRequest request) throws Exception {
    if (listing != null) {
        return listing;
    }/*  w  w w  .ja v a  2s . c o m*/

    ObjectListing localListing = new ObjectListing();
    for (String key : uploads.keySet()) {
        boolean addIt = false;
        if (request.getPrefix() != null) {
            if (key.startsWith(request.getPrefix())) {
                addIt = true;
            }
        }

        if (addIt) {
            S3ObjectSummary summary = new S3ObjectSummary();
            summary.setKey(key);
            localListing.getObjectSummaries().add(summary);
        }
    }
    return localListing;
}

From source file:com.netflix.exhibitor.core.backup.s3.MockS3Client.java

License:Apache License

@Override
public ObjectListing listNextBatchOfObjects(ObjectListing previousObjectListing) throws Exception {
    ObjectListing listing = new ObjectListing();
    listing.setTruncated(false);//from w w w.  jav a2s .c o  m
    return listing;
}

From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java

License:Open Source License

/**
 * list all objects without and return ObjectListing with all elements
 * and with truncated to false/*ww w . j  a v a 2s  . co  m*/
 */
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException {

    ObjectListing objectListing = new ObjectListing();
    objectListing.setBucketName(listObjectsRequest.getBucketName());
    objectListing.setPrefix(listObjectsRequest.getPrefix());
    objectListing.setMarker(listObjectsRequest.getMarker());
    objectListing.setDelimiter(listObjectsRequest.getDelimiter());

    Bucket bucket = find(listObjectsRequest.getBucketName());
    Iterator<S3Element> iterator = objects.get(bucket).iterator();

    int i = 0;

    while (iterator.hasNext()) {

        S3Element elem = iterator.next();

        // TODO. add delimiter and marker support
        if (listObjectsRequest.getPrefix() != null
                && elem.getS3Object().getKey().startsWith(listObjectsRequest.getPrefix())) {

            S3ObjectSummary s3ObjectSummary = parseToS3ObjectSummary(elem);
            objectListing.getObjectSummaries().add(s3ObjectSummary);

            if (i + 1 == LIMIT_AWS_MAX_ELEMENTS && iterator.hasNext()) {
                objectListing.setTruncated(true);
                objectListing.setNextMarker(iterator.next().getS3Object().getKey());
                return objectListing;
            } else {
                objectListing.setTruncated(false);
            }

            i++;
        }

    }

    return objectListing;
}

From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java

License:Open Source License

@Override
public ObjectListing listNextBatchOfObjects(ObjectListing previousObjectListing) {

    ObjectListing objectListing = new ObjectListing();
    objectListing.setBucketName(previousObjectListing.getBucketName());
    objectListing.setPrefix(previousObjectListing.getPrefix());
    objectListing.setMarker(previousObjectListing.getMarker());
    objectListing.setDelimiter(previousObjectListing.getDelimiter());

    if (!previousObjectListing.isTruncated() || previousObjectListing.getNextMarker() == null) {
        return objectListing;
    }//from   w  ww  .  ja v a2 s .  c  o  m

    Bucket bucket = find(previousObjectListing.getBucketName());
    Iterator<S3Element> iterator = objects.get(bucket).iterator();

    int i = 0;
    boolean continueElement = false;

    while (iterator.hasNext()) {

        S3Element elem = iterator.next();

        if (!continueElement && elem.getS3Object().getKey().equals(previousObjectListing.getNextMarker())) {
            continueElement = true;
        }

        if (continueElement) {
            // TODO. add delimiter and marker support
            if (previousObjectListing.getPrefix() != null
                    && elem.getS3Object().getKey().startsWith(previousObjectListing.getPrefix())) {

                S3ObjectSummary s3ObjectSummary = parseToS3ObjectSummary(elem);
                objectListing.getObjectSummaries().add(s3ObjectSummary);
                // max 1000 elements at same time.
                if (i + 1 == LIMIT_AWS_MAX_ELEMENTS && iterator.hasNext()) {
                    objectListing.setTruncated(true);
                    objectListing.setNextMarker(iterator.next().getS3Object().getKey());
                    return objectListing;
                } else {
                    objectListing.setTruncated(false);
                }

                i++;
            }
        }
    }

    return objectListing;
}

From source file:edu.si.services.beans.cameratrap.AmazonS3ClientMock.java

License:Apache License

@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws AmazonClientException, AmazonServiceException {
    if ("nonExistingBucket".equals(listObjectsRequest.getBucketName()) && !nonExistingBucketCreated) {
        AmazonServiceException ex = new AmazonServiceException("Unknown bucket");
        ex.setStatusCode(404);/*w  w  w .  j a  v  a2 s  . c  o m*/
        throw ex;
    }
    ObjectListing objectListing = new ObjectListing();
    for (int index = 0; index < objects.size(); index++) {
        if (objects.get(index).getBucketName().equals(listObjectsRequest.getBucketName())) {
            S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
            s3ObjectSummary.setBucketName(objects.get(index).getBucketName());
            s3ObjectSummary.setKey(objects.get(index).getKey());

            objectListing.getObjectSummaries().add(s3ObjectSummary);
        }
    }

    return objectListing;
}

From source file:org.apache.camel.component.aws.s3.AmazonS3ClientMock.java

License:Apache License

@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws AmazonClientException, AmazonServiceException {
    if ("nonExistingBucket".equals(listObjectsRequest.getBucketName()) && !nonExistingBucketCreated) {
        AmazonServiceException ex = new AmazonServiceException("Unknow bucket");
        ex.setStatusCode(404);//w  ww.  j a  v  a 2 s .  co m
        throw ex;
    }

    ObjectListing objectListing = new ObjectListing();
    int capacity = listObjectsRequest.getMaxKeys();

    for (int index = 0; index < objects.size() && index < capacity; index++) {
        S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
        s3ObjectSummary.setBucketName(objects.get(index).getBucketName());
        s3ObjectSummary.setKey(objects.get(index).getKey());

        objectListing.getObjectSummaries().add(s3ObjectSummary);
    }

    return objectListing;
}

From source file:org.apache.camel.itest.osgi.aws.AmazonS3ClientMock.java

License:Apache License

@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws AmazonClientException, AmazonServiceException {
    ObjectListing objectListing = new ObjectListing();
    int capacity = listObjectsRequest.getMaxKeys();

    for (int index = 0; index < objects.size() && index < capacity; index++) {
        S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
        s3ObjectSummary.setBucketName(objects.get(index).getBucketName());
        s3ObjectSummary.setKey(objects.get(index).getKey());

        objectListing.getObjectSummaries().add(s3ObjectSummary);
    }/* ww w .j av  a 2s .c  o m*/

    return objectListing;
}

From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java

License:Apache License

/**
 * Returns a list of objects. If the bucket does not exist, returns a listing with an empty list.
 * If a prefix is specified in listObjectsRequest, only keys starting with the prefix will be returned.
 *///  w w w.  java  2  s.  c om
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest, AmazonS3Client s3Client) {
    LOGGER.debug("listObjects(): listObjectsRequest.getBucketName() = " + listObjectsRequest.getBucketName());

    String bucketName = listObjectsRequest.getBucketName();

    if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName)) {
        AmazonS3Exception amazonS3Exception = new AmazonS3Exception(
                MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
        amazonS3Exception.setErrorCode("NoSuchBucket");
        throw amazonS3Exception;
    }

    ObjectListing objectListing = new ObjectListing();
    objectListing.setBucketName(bucketName);

    MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
    if (mockS3Bucket != null) {
        for (MockS3Object mockS3Object : mockS3Bucket.getObjects().values()) {
            String s3ObjectKey = mockS3Object.getKey();
            if (listObjectsRequest.getPrefix() == null
                    || s3ObjectKey.startsWith(listObjectsRequest.getPrefix())) {
                S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
                s3ObjectSummary.setBucketName(bucketName);
                s3ObjectSummary.setKey(s3ObjectKey);
                s3ObjectSummary.setSize(mockS3Object.getData().length);

                objectListing.getObjectSummaries().add(s3ObjectSummary);
            }
        }
    }

    return objectListing;
}

From source file:org.finra.herd.dao.impl.MockS3OperationsImpl.java

License:Apache License

/**
 * {@inheritDoc}/*from  www.  j a va2  s .  c o m*/
 * <p/>
 * If the bucket does not exist, returns a listing with an empty list. If a prefix is specified in listObjectsRequest, only keys starting with the prefix
 * will be returned.
 */
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest, AmazonS3 s3Client) {
    LOGGER.debug("listObjects(): listObjectsRequest.getBucketName() = " + listObjectsRequest.getBucketName());

    String bucketName = listObjectsRequest.getBucketName();

    if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName)) {
        AmazonS3Exception amazonS3Exception = new AmazonS3Exception(
                MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION);
        amazonS3Exception.setErrorCode("NoSuchBucket");
        throw amazonS3Exception;
    }

    ObjectListing objectListing = new ObjectListing();
    objectListing.setBucketName(bucketName);

    MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucketName);
    if (mockS3Bucket != null) {
        for (MockS3Object mockS3Object : mockS3Bucket.getObjects().values()) {
            String s3ObjectKey = mockS3Object.getKey();
            if (listObjectsRequest.getPrefix() == null
                    || s3ObjectKey.startsWith(listObjectsRequest.getPrefix())) {
                S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
                s3ObjectSummary.setBucketName(bucketName);
                s3ObjectSummary.setKey(s3ObjectKey);
                s3ObjectSummary.setSize(mockS3Object.getData().length);
                s3ObjectSummary.setStorageClass(mockS3Object.getObjectMetadata() != null
                        ? mockS3Object.getObjectMetadata().getStorageClass()
                        : null);

                objectListing.getObjectSummaries().add(s3ObjectSummary);
            }
        }
    }

    return objectListing;
}

From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java

License:Apache License

@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws AmazonClientException, AmazonServiceException {
    ObjectListing objectListing = new ObjectListing();
    Integer capacity = listObjectsRequest.getMaxKeys();
    if (capacity == null) {
        capacity = Integer.MAX_VALUE;
    }//from w  w w  . j  av  a  2  s.  c o  m

    Bucket bucket = find(listObjectsRequest.getBucketName());
    for (S3Element elem : objects.get(bucket)) {
        if (capacity > 0) {
            // TODO. add delimiter and marker support
            if (listObjectsRequest.getPrefix() != null
                    && elem.getS3Object().getKey().startsWith(listObjectsRequest.getPrefix())) {
                S3ObjectSummary s3ObjectSummary = new S3ObjectSummary();
                s3ObjectSummary.setBucketName(elem.getS3Object().getBucketName());
                s3ObjectSummary.setKey(elem.getS3Object().getKey());
                s3ObjectSummary.setLastModified(elem.getS3Object().getObjectMetadata().getLastModified());
                s3ObjectSummary.setOwner(owner);
                s3ObjectSummary.setETag(elem.getS3Object().getObjectMetadata().getETag());
                s3ObjectSummary.setSize(elem.getS3Object().getObjectMetadata().getContentLength());
                objectListing.getObjectSummaries().add(s3ObjectSummary);
                capacity--;
            }
        }

    }

    return objectListing;
}