List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary S3ObjectSummary
S3ObjectSummary
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; }/*from w w w.j a va 2s . co 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.treasure_data.td_import.source.S3Source.java
License:Apache License
static List<S3ObjectSummary> getSources(AmazonS3Client client, String bucket, String basePath) { String prefix;/*from w w w .jav a 2 s . co m*/ int index = basePath.indexOf('*'); if (index >= 0) { prefix = basePath.substring(0, index); } else { ObjectMetadata om = client.getObjectMetadata(bucket, basePath); S3ObjectSummary s3object = new S3ObjectSummary(); s3object.setBucketName(bucket); s3object.setKey(basePath); s3object.setSize(om.getContentLength()); return Arrays.asList(s3object); } LOG.info(String.format("list s3 files by client %s: bucket=%s, basePath=%s, prefix=%s", client, bucket, basePath, prefix)); List<S3ObjectSummary> s3objects = new ArrayList<S3ObjectSummary>(); String lastKey = prefix; do { ObjectListing listing = client.listObjects(new ListObjectsRequest(bucket, prefix, lastKey, null, 1024)); for (S3ObjectSummary s3object : listing.getObjectSummaries()) { s3objects.add(s3object); } lastKey = listing.getNextMarker(); } while (lastKey != null); return filterSources(s3objects, basePath); }
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 av a 2s .c o 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 *//*from w ww .ja v 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: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);/* ww w . j a v a 2 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);/*from w ww. j a v a2 s . c o 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); }//from w w w. j a v a 2s .co m return objectListing; }
From source file:org.apache.tajo.storage.s3.MockObjectListing.java
License:Apache License
private S3ObjectSummary getS3ObjectSummary(String bucketName, String key, long size) { S3ObjectSummary objectSummary = new S3ObjectSummary(); objectSummary.setBucketName(bucketName); objectSummary.setKey(key);/*w w w. j a v a2 s. c o m*/ objectSummary.setSize(size); return objectSummary; }
From source file:org.elasticsearch.cloud.aws.blobstore.MockAmazonS3.java
License:Apache License
@Override public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException, AmazonServiceException { MockObjectListing list = new MockObjectListing(); list.setTruncated(false);//from ww w.j a v a 2s. co m String blobName; String prefix = listObjectsRequest.getPrefix(); ArrayList<S3ObjectSummary> mockObjectSummaries = new ArrayList<>(); for (Map.Entry<String, InputStream> blob : blobs.entrySet()) { blobName = blob.getKey(); S3ObjectSummary objectSummary = new S3ObjectSummary(); if (prefix.isEmpty() || blobName.startsWith(prefix)) { objectSummary.setKey(blobName); try { objectSummary.setSize(getSize(blob.getValue())); } catch (IOException e) { throw new AmazonS3Exception("Object listing " + "failed for blob [" + blob.getKey() + "]"); } mockObjectSummaries.add(objectSummary); } } list.setObjectSummaries(mockObjectSummaries); return list; }
From source file:org.elasticsearch.repositories.s3.MockAmazonS3.java
License:Apache License
@Override public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException, AmazonServiceException { simulateS3SocketConnection();/* w w w. ja v a2 s . co m*/ MockObjectListing list = new MockObjectListing(); list.setTruncated(false); String blobName; String prefix = listObjectsRequest.getPrefix(); ArrayList<S3ObjectSummary> mockObjectSummaries = new ArrayList<>(); for (Map.Entry<String, InputStream> blob : blobs.entrySet()) { blobName = blob.getKey(); S3ObjectSummary objectSummary = new S3ObjectSummary(); if (prefix.isEmpty() || blobName.startsWith(prefix)) { objectSummary.setKey(blobName); try { objectSummary.setSize(getSize(blob.getValue())); } catch (IOException e) { throw new AmazonS3Exception("Object listing " + "failed for blob [" + blob.getKey() + "]"); } mockObjectSummaries.add(objectSummary); } } list.setObjectSummaries(mockObjectSummaries); return list; }