List of usage examples for com.amazonaws.services.s3 AmazonS3 listObjects
public ObjectListing listObjects(String bucketName, String prefix) throws SdkClientException, AmazonServiceException;
Returns a list of summary information about the objects in the specified bucket.
From source file:org.serginho.awss3conn.Connection.java
public List<S3ObjectSummary> getFileList() { AmazonS3 s3Client = getS3Client(); ObjectListing objects = s3Client.listObjects(this.amazonBucket, this.key); List<S3ObjectSummary> fileList = new ArrayList<S3ObjectSummary>(); do {//from w w w.j a va2 s. com for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { if (objectSummary.getSize() != 0) // We don't need to display the root "key" (folder) fileList.add(objectSummary); } objects = s3Client.listNextBatchOfObjects(objects); } while (objects.isTruncated()); return fileList; }
From source file:org.springframework.aws.ivy.S3Resource.java
License:Apache License
public S3Resource(AmazonS3 service, String uri) { this.service = service; this.uri = uri; ObjectListing objects = service.listObjects(S3Utils.getBucket(uri), S3Utils.getKey(uri)); if (objects.getObjectSummaries().size() == 0) { summary = null;// w w w. j a v a2 s. co m } else { summary = objects.getObjectSummaries().get(0); } }
From source file:org.xmlsh.aws.gradle.s3.AmazonS3DeleteAllFilesTask.java
License:BSD License
@TaskAction public void delete() { // to enable conventionMappings feature String bucketName = getBucketName(); String prefix = getPrefix();//w ww. ja v a2 s . c om if (bucketName == null) throw new GradleException("bucketName is not specified"); AmazonS3PluginExtension ext = getProject().getExtensions().getByType(AmazonS3PluginExtension.class); AmazonS3 s3 = ext.getClient(); if (prefix.startsWith("/")) { prefix = prefix.substring(1); } getLogger().info("Delete s3://{}/{}*", bucketName, prefix); List<S3ObjectSummary> objectSummaries; while ((objectSummaries = s3.listObjects(bucketName, prefix).getObjectSummaries()).isEmpty() == false) { objectSummaries.forEach(os -> { getLogger().info(" Deleting... s3://{}/{}", bucketName, os.getKey()); s3.deleteObject(bucketName, os.getKey()); }); } }