本文整理汇总了Java中com.amazonaws.services.s3.model.ObjectListing.getObjectSummaries方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectListing.getObjectSummaries方法的具体用法?Java ObjectListing.getObjectSummaries怎么用?Java ObjectListing.getObjectSummaries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.s3.model.ObjectListing
的用法示例。
在下文中一共展示了ObjectListing.getObjectSummaries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteAll
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public void deleteAll(String bucket) {
logger.info("delete all from bucket, bucket={}", bucket);
ObjectListing listing = s3.listObjects(new ListObjectsRequest().withBucketName(bucket));
while (listing != null) {
List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<>(listing.getObjectSummaries().size());
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
String key = summary.getKey();
logger.info("add key to deletion batch, key={}", key);
keys.add(new DeleteObjectsRequest.KeyVersion(key));
}
if (!keys.isEmpty()) {
logger.info("delete key batch");
s3.deleteObjects(new DeleteObjectsRequest(bucket).withKeys(keys));
}
if (!listing.isTruncated()) return;
listing = s3.listNextBatchOfObjects(listing);
}
}
示例2: getFileList
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public void getFileList(String path, OutputStream out) throws Exception {
String marker = null;
do {
ListObjectsRequest request = new ListObjectsRequest(bucketName, path, null, "/", 1000);
ObjectListing listing = client.listObjects(request);
for (S3ObjectSummary object : listing.getObjectSummaries()) {
String line = object.getKey() + "\n";
out.write(line.getBytes());
}
for (String commonPrefix : listing.getCommonPrefixes()) {
getFileList(commonPrefix, out);
}
marker = listing.getNextMarker();
} while (marker != null);
}
示例3: list
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unused")
public List<AwsFileMiniModel> list(String prefix) {
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
List<AwsFileMiniModel> files = new ArrayList();
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(prefix);
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"
+ " (date = " + objectSummary.getLastModified() + ")");
files.add(new AwsFileMiniModel(objectSummary.getKey(), objectSummary.getLastModified()));
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
return files;
}
示例4: deleteByTenant
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public void deleteByTenant(final String tenant) {
final String folder = sanitizeTenant(tenant);
LOG.info("Deleting S3 object folder (tenant) from bucket {} and key {}", s3Properties.getBucketName(), folder);
// Delete artifacts
ObjectListing objects = amazonS3.listObjects(s3Properties.getBucketName(), folder + "/");
do {
for (final S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
amazonS3.deleteObject(s3Properties.getBucketName(), objectSummary.getKey());
}
objects = amazonS3.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
}
示例5: main
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public static void main(String[] args)
{
final String USAGE = "\n" +
"To run this example, supply the name of a bucket to list!\n" +
"\n" +
"Ex: ListObjects <bucket-name>\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
System.out.format("Objects in S3 bucket %s:\n", bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
ObjectListing ol = s3.listObjects(bucket_name);
List<S3ObjectSummary> objects = ol.getObjectSummaries();
for (S3ObjectSummary os: objects) {
System.out.println("* " + os.getKey());
}
}
示例6: list
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public List<NoteInfo> list(AuthenticationInfo subject) throws IOException {
List<NoteInfo> infos = new LinkedList<>();
NoteInfo info;
try {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName)
.withPrefix(user + "/" + "notebook");
ObjectListing objectListing;
do {
objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
if (objectSummary.getKey().endsWith("note.json")) {
info = getNoteInfo(objectSummary.getKey());
if (info != null) {
infos.add(info);
}
}
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
} catch (AmazonClientException ace) {
throw new IOException("Unable to list objects in S3: " + ace, ace);
}
return infos;
}
示例7: remove
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
String key = user + "/" + "notebook" + "/" + noteId;
final ListObjectsRequest listObjectsRequest = new ListObjectsRequest()
.withBucketName(bucketName).withPrefix(key);
try {
ObjectListing objects = s3client.listObjects(listObjectsRequest);
do {
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
s3client.deleteObject(bucketName, objectSummary.getKey());
}
objects = s3client.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
}
catch (AmazonClientException ace) {
throw new IOException("Unable to remove note in S3: " + ace, ace);
}
}
示例8: getAllChildren
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public ArrayList<String> getAllChildren(String folderName) throws IOException {
ListObjectsRequest listRequest = new ListObjectsRequest();
listRequest.setBucketName(getBucketName());
listRequest.setPrefix(folderName);
ObjectListing listing = s3.listObjects(listRequest);
ArrayList<String> list = new ArrayList<String>();
System.out.println(listing.getObjectSummaries().size());
for (S3ObjectSummary summ : listing.getObjectSummaries()) {
list.add(summ.getKey());
}
return list;
}
示例9: listBucket
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
public List<String> listBucket(String bkt, String prefix, String delimiter) throws IOException {
ListObjectsRequest listRequest = new ListObjectsRequest();
listRequest.setBucketName(bkt);
listRequest.setDelimiter(delimiter);
listRequest.setPrefix(prefix);
ObjectListing listing = s3.listObjects(listRequest);
ArrayList<String> list = new ArrayList<String>();
for (S3ObjectSummary summ : listing.getObjectSummaries()) {
list.add(summ.getKey());
}
return list;
}
示例10: afterSpiStopped
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
/**
* @throws Exception If error.
*/
@Override protected void afterSpiStopped() throws Exception {
AWSCredentials cred = new BasicAWSCredentials(IgniteS3TestSuite.getAccessKey(),
IgniteS3TestSuite.getSecretKey());
AmazonS3 s3 = new AmazonS3Client(cred);
String bucketName = S3CheckpointSpi.BUCKET_NAME_PREFIX + "unit-test-bucket";
try {
ObjectListing list = s3.listObjects(bucketName);
while (true) {
for (S3ObjectSummary sum : list.getObjectSummaries())
s3.deleteObject(bucketName, sum.getKey());
if (list.isTruncated())
list = s3.listNextBatchOfObjects(list);
else
break;
}
}
catch (AmazonClientException e) {
throw new IgniteSpiException("Failed to read checkpoint bucket: " + bucketName, e);
}
}
示例11: testListObjectsWithNoPathWithPrefix
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Test
public void testListObjectsWithNoPathWithPrefix() throws Exception {
client.createBucket("test-bucket");
putObject("test-bucket", "no-path-1", "foobar");
putObject("test-bucket", "no-path-2", "");
putObject("test-bucket", "/one/prefix-1.xml", "foobar");
putObject("test-bucket", "/no-path/two/prefix-1.xml", "foobar");
putObject("test-bucket", "/two/prefix-1.xml", "foobar");
putObject("test-bucket", "/file/with/loads/of/slashes-3.png", "dfsrgt3");
ObjectListing objectListing = client.listObjects("test-bucket", "no-path");
List<String> objectKeys = new ArrayList<>();
for(S3ObjectSummary s3ObjectSummary : objectListing.getObjectSummaries()) {
assertEquals("test-bucket", s3ObjectSummary.getBucketName());
objectKeys.add(s3ObjectSummary.getKey());
}
assertEquals(3, objectKeys.size());
assertTrue(objectKeys.contains("no-path-1"));
assertTrue(objectKeys.contains("no-path-2"));
assertTrue(objectKeys.contains("/no-path/two/prefix-1.xml"));
}
示例12: deleteCollection
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public void deleteCollection(Map<String, Object> attributes, String collectionName)
throws IOException
{
if (s3Client==null) {
throw new IOException("S3 Client is not available due to configuration error.");
}
String bucketName = getBucketName(attributes);
if (bucketName==null) {
throw new IOException("S3 Bucket not configured for "+attributes.get("app.database"));
}
try {
ObjectListing listing = null;
do {
listing = listing==null ? s3Client.listObjects(bucketName, collectionName+"/") : s3Client.listNextBatchOfObjects(listing);
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
s3Client.deleteObject(bucketName, summary.getKey());
}
} while (listing.isTruncated());
} catch (AmazonClientException ex) {
throw new IOException("Cannot delete collection objects due to S3 error.",ex);
}
}
示例13: getFilenamesFromListing
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
private List<String> getFilenamesFromListing(ObjectListing listing, String prefix) {
List<String> results = new ArrayList<String>(100);
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
final String key = summary.getKey();
final String filename;
filename = key.substring(prefix.length());
if (filename.length() == 0 || filename.contains(DELIMITER)) {
log.error("Error parsing S3 object Key. Key: " + key);
continue;
}
results.add(filename);
}
return results;
}
示例14: list
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Override
public List<String> list() {
List<String> files = new ArrayList<String>();
if(s3URI == null) return files;
String[] buckAndKey = this.getBucketAndKey();
String bucket = buckAndKey[0];
String key = buckAndKey[1];
ObjectListing objectListing = s3. listObjects(new ListObjectsRequest().withBucketName(bucket).withPrefix(key));
s3list: for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
// check for valid extensions
if(extensions == null){
files.add("s3://"+bucket+"/"+objectSummary.getKey());
} else for(String ext : extensions) if(objectSummary.getKey().endsWith(ext)){
files.add("s3://"+bucket+"/"+objectSummary.getKey());
continue s3list;
}
}
return files;
}
示例15: testEmptyBucketReturnsExpectedObjects
import com.amazonaws.services.s3.model.ObjectListing; //导入方法依赖的package包/类
@Test
public void testEmptyBucketReturnsExpectedObjects() throws Exception {
client.createBucket("test-bucket");
putObject("test-bucket", "file-1", "foobar");
putObject("test-bucket", "file-2", "");
putObject("test-bucket", "/file/with/slashes-1.xml", "foobar");
putObject("test-bucket", "/file/with/loads/of/slashes-3.png", "dfsrgt3");
ObjectListing objectListing = client.listObjects("test-bucket");
List<String> objectKeys = new ArrayList<>();
for(S3ObjectSummary s3ObjectSummary : objectListing.getObjectSummaries()) {
assertEquals("test-bucket", s3ObjectSummary.getBucketName());
objectKeys.add(s3ObjectSummary.getKey());
}
assertEquals(4, objectKeys.size());
assertTrue(objectKeys.contains("file-1"));
assertTrue(objectKeys.contains("file-2"));
assertTrue(objectKeys.contains("/file/with/slashes-1.xml"));
assertTrue(objectKeys.contains("/file/with/loads/of/slashes-3.png"));
}