List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary getKey
public String getKey()
From source file:org.springframework.aws.ivy.S3Repository.java
License:Apache License
public List<String> list(String parent) throws IOException { String bucket = S3Utils.getBucket(parent); String key = S3Utils.getKey(parent); String marker = null;/*ww w .ja v a 2 s. com*/ List<String> keys = new ArrayList<String>(); do { ObjectListing objects = getService().listObjects( new ListObjectsRequest().withBucketName(bucket).withPrefix(key).withMarker(marker)); for (S3ObjectSummary summary : objects.getObjectSummaries()) { String uri = "s3://" + bucket + "/" + summary.getKey(); if (!uri.equals(parent)) { keys.add(uri); resourceCache.put(uri, new S3Resource(service, summary)); } } marker = objects.getNextMarker(); } while (marker != null); return keys; }
From source file:org.springframework.aws.ivy.S3Resource.java
License:Apache License
public S3Resource(AmazonS3 service, S3ObjectSummary summary) { this.service = service; this.summary = summary; this.uri = "s3://" + summary.getBucketName() + "/" + summary.getKey(); }
From source file:org.springframework.cloud.aws.core.io.s3.PathMatchingSimpleStorageResourcePatternResolver.java
License:Apache License
private Set<Resource> getResourcesFromObjectSummaries(String bucketName, String keyPattern, List<S3ObjectSummary> objectSummaries) { Set<Resource> resources = new HashSet<>(); for (S3ObjectSummary objectSummary : objectSummaries) { String keyPath = SimpleStorageNameUtils.getLocationForBucketAndObject(bucketName, objectSummary.getKey()); if (this.pathMatcher.match(keyPattern, objectSummary.getKey())) { Resource resource = this.simpleStorageResourceLoader.getResource(keyPath); if (resource.exists()) { resources.add(resource); }/*from w ww. j a va 2 s. c om*/ } } return resources; }
From source file:org.springframework.integration.aws.inbound.S3InboundFileSynchronizer.java
License:Apache License
@Override protected String getFilename(S3ObjectSummary file) { return (file != null ? file.getKey() : null); }
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 . j a va 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 w w w.ja v a2 s .co 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; }
From source file:org.springframework.integration.aws.support.filters.S3PersistentAcceptOnceFileListFilter.java
License:Apache License
@Override protected String fileName(S3ObjectSummary file) { return (file != null) ? file.getKey() : null; }
From source file:org.springframework.integration.aws.support.filters.S3RegexPatternFileListFilter.java
License:Apache License
@Override protected String getFilename(S3ObjectSummary file) { return (file != null) ? file.getKey() : null; }
From source file:org.springframework.integration.aws.support.S3Session.java
License:Apache License
@Override public String[] listNames(String path) throws IOException { String[] bucketPrefix = path.split("/"); Assert.state(bucketPrefix.length > 0 && bucketPrefix[0].length() >= 3, "S3 bucket name must be at least 3 characters long."); String bucket = resolveBucket(bucketPrefix[0]); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket); if (bucketPrefix.length > 1) { listObjectsRequest.setPrefix(bucketPrefix[1]); }/*from w w w . j av a 2 s . c o m*/ /* For listing objects, Amazon S3 returns up to 1,000 keys in the response. If you have more than 1,000 keys in your bucket, the response will be truncated. You should always check for if the response is truncated. */ ObjectListing objectListing; List<String> names = new ArrayList<>(); do { objectListing = this.amazonS3.listObjects(listObjectsRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { names.add(objectSummary.getKey()); } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); return names.toArray(new String[names.size()]); }
From source file:org.symphonyoss.vb.mail.MailReader.java
License:Apache License
public List<SymMessage> getMessages(String bucket, String prefix) { AwsS3Client awsS3Client = new AwsS3Client(); List<SymMessage> messages = new ArrayList<>(); List<S3ObjectSummary> objectSummaries = awsS3Client.getAllObjects(System.getProperty(BotConfig.S3_BUCKET), System.getProperty(BotConfig.MAIL_S3_PREFIX_INCOMING)); for (S3ObjectSummary objectSummary : objectSummaries) { if (objectSummary.getKey().equals(prefix)) continue; logger.info("New mail file: {}:{}:{}", objectSummary.getKey(), objectSummary.getSize(), objectSummary.getLastModified()); try {/*from ww w . j av a 2 s . co m*/ Message message = Mailer.getMessage(awsS3Client.getObject(objectSummary)); //Couldn't convert it. if (message == null) continue; try { SymMessage symMessage = getSymMessage(message); if (symMessage != null) { logger.info("New mail message: from: {}, subject: {}, body: {}", symMessage.getSymUser().getEmailAddress(), message.getSubject(), symMessage.getMessage()); messages.add(symMessage); } } catch (SymException ex) { logger.error("Could not convert email to SymMessage from file [{}]", objectSummary.getKey(), ex); } String destKey = objectSummary.getKey().substring(objectSummary.getKey().lastIndexOf("/") + 1); //logger.info("DEST FILE: {}", destKey); awsS3Client.moveObject(objectSummary, System.getProperty(BotConfig.S3_BUCKET), System.getProperty(BotConfig.MAIL_S3_PREFIX_PROCESSED) + destKey); } catch (Exception e) { logger.error("Failed to process incoming email [{}]", objectSummary.getKey(), e); } } return messages; }