Example usage for com.amazonaws.services.s3.model S3ObjectSummary setETag

List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary setETag

Introduction

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

Prototype

public void setETag(String eTag) 

Source Link

Document

Sets the hex encoded 128-bit MD5 hash of this object's contents as computed by Amazon S3.

Usage

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

License:Open Source License

/**
 * create a new S3ObjectSummary using the S3Element
 * @param elem S3Element to parse/*from  w  ww . j a  va2s . co m*/
 * @return S3ObjectSummary
 */
private S3ObjectSummary parseToS3ObjectSummary(S3Element elem) {
    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());

    return s3ObjectSummary;
}

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

License:Open Source License

/**
 * Get the {@link com.amazonaws.services.s3.model.S3ObjectSummary} that represent this Path or her first child if this path not exists
 * @param s3Path {@link com.upplication.s3fs.S3Path}
 * @return {@link com.amazonaws.services.s3.model.S3ObjectSummary}
 * @throws java.nio.file.NoSuchFileException if not found the path and any child
 *///  w ww . j av  a  2  s .c  o  m
public S3ObjectSummary lookup(S3Path s3Path) throws NoSuchFileException {

    /*
     * check is object summary has been cached
     */
    S3ObjectSummary summary = s3Path.fetchObjectSummary();
    if (summary != null) {
        return summary;
    }

    final AmazonS3Client client = s3Path.getFileSystem().getClient();

    /*
     * when `key` is an empty string retrieve the object meta-data of the bucket
     */
    if ("".equals(s3Path.getKey())) {
        ObjectMetadata meta = client.getObjectMetadata(s3Path.getBucket(), "");
        if (meta == null)
            throw new NoSuchFileException("s3://" + s3Path.getBucket());

        summary = new S3ObjectSummary();
        summary.setBucketName(s3Path.getBucket());
        summary.setETag(meta.getETag());
        summary.setKey(s3Path.getKey());
        summary.setLastModified(meta.getLastModified());
        summary.setSize(meta.getContentLength());
        // TODO summary.setOwner(?);
        // TODO summary.setStorageClass(?);
        return summary;
    }

    /*
     * Lookup for the object summary for the specified object key
     * by using a `listObjects` request
     */
    String marker = null;
    while (true) {
        ListObjectsRequest request = new ListObjectsRequest();
        request.setBucketName(s3Path.getBucket());
        request.setPrefix(s3Path.getKey());
        request.setMaxKeys(250);
        if (marker != null)
            request.setMarker(marker);

        ObjectListing listing = client.listObjects(request);
        List<S3ObjectSummary> results = listing.getObjectSummaries();

        if (results.isEmpty()) {
            break;
        }

        for (S3ObjectSummary item : results) {
            if (matchName(s3Path.getKey(), item)) {
                return item;
            }
        }

        if (listing.isTruncated())
            marker = listing.getNextMarker();
        else
            break;
    }

    throw new NoSuchFileException("s3://" + s3Path.getBucket() + "/" + s3Path.toString());
}

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   www. j a va  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;
}