List of usage examples for com.amazonaws.services.s3 AmazonS3Client listNextBatchOfObjects
@Override public ObjectListing listNextBatchOfObjects(ListNextBatchOfObjectsRequest listNextBatchOfObjectsRequest) throws SdkClientException, AmazonServiceException
From source file:org.entando.entando.plugins.jps3awsclient.aps.system.services.storage.AmazonS3StorageManager.java
License:Open Source License
public void delete(String bucketName, String key) throws ApsSystemException { if (!this.isActive()) { return;//from w ww .j a v a2s . c o m } try { if (key == null || key.trim().length() == 0) { _logger.warn("Empty storage path passed to delete method"); return; // We don't want to delete everything in a path } AmazonS3Client client = this.getS3Client(); // Go through the store structure and delete child objects ObjectListing listing = this.getS3Client().listObjects(bucketName, key); while (true) { List<S3ObjectSummary> objectList = listing.getObjectSummaries(); for (int i = 0; i < objectList.size(); i++) { S3ObjectSummary summary = objectList.get(i); client.deleteObject(bucketName, summary.getKey()); } if (listing.isTruncated()) { listing = client.listNextBatchOfObjects(listing); } else { break; } } } catch (Throwable t) { _logger.error("Error deleting objects : bucket {} - key {}", bucketName, key, t); throw new ApsSystemException("Error deleting objects : bucket " + bucketName + " - key " + key, t); } }
From source file:org.zalando.stups.fullstop.controller.S3Controller.java
License:Apache License
@RequestMapping(method = RequestMethod.GET, value = "/download") public void downloadFiles(@RequestParam(value = "bucket") final String bucket, @RequestParam(value = "location") final String location, @RequestParam(value = "page") final int page) { try {//from ww w. j a va2 s. c o m log.info("Creating fullstop directory here: {}", fullstopLoggingDir); boolean mkdirs = new File(fullstopLoggingDir).mkdirs(); } catch (SecurityException e) { // do nothing } AmazonS3Client amazonS3Client = new AmazonS3Client(); amazonS3Client.setRegion(Region.getRegion(Regions .fromName((String) cloudTrailProcessingLibraryProperties.getAsProperties().get(S3_REGION_KEY)))); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket) // .withPrefix(location) // .withMaxKeys(page); ObjectListing objectListing = amazonS3Client.listObjects(listObjectsRequest); final List<S3ObjectSummary> s3ObjectSummaries = objectListing.getObjectSummaries(); while (objectListing.isTruncated()) { objectListing = amazonS3Client.listNextBatchOfObjects(objectListing); s3ObjectSummaries.addAll(objectListing.getObjectSummaries()); } for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries) { String bucketName = s3ObjectSummary.getBucketName(); String key = s3ObjectSummary.getKey(); S3Object object = amazonS3Client.getObject(new GetObjectRequest(bucketName, key)); InputStream inputStream = object.getObjectContent(); File file = new File(fullstopLoggingDir, object.getBucketName() + object.getObjectMetadata().getETag() + JSON_GZ); copyInputStreamToFile(inputStream, file); log.info("File saved here: {}", file.getAbsolutePath()); } }