List of usage examples for com.amazonaws.services.s3.model ObjectListing getObjectSummaries
public List<S3ObjectSummary> getObjectSummaries()
From source file:io.dockstore.webservice.core.tooltester.ToolTesterS3Client.java
License:Apache License
private List<ToolTesterLog> convertObjectListingToTooltesterLogs(ObjectListing firstListing) { ObjectListing listing = firstListing; List<S3ObjectSummary> summaries = listing.getObjectSummaries(); while (listing.isTruncated()) { listing = s3.listNextBatchOfObjects(listing); summaries.addAll(listing.getObjectSummaries()); }// w w w. j av a 2 s . c o m return summaries.stream().map(summary -> { ObjectMetadata objectMetadata = s3.getObjectMetadata(bucketName, summary.getKey()); Map<String, String> userMetadata = objectMetadata.getUserMetadata(); String filename = getFilenameFromSummary(summary); return convertUserMetadataToToolTesterLog(userMetadata, filename); }).collect(Collectors.toList()); }
From source file:io.konig.camel.aws.s3.DeleteObjectConsumer.java
License:Apache License
@Override protected int poll() throws Exception { // must reset for each poll shutdownRunningTask = null;//from ww w. j a v a 2 s .c o m pendingExchanges = 0; String fileName = getConfiguration().getFileName(); String bucketName = getConfiguration().getBucketName(); Queue<Exchange> exchanges; if (fileName != null) { LOG.trace("Getting object in bucket [{}] with file name [{}]...", bucketName, fileName); S3Object s3Object = getAmazonS3Client().getObject(new GetObjectRequest(bucketName, fileName)); exchanges = createExchanges(s3Object); } else { LOG.trace("Queueing objects in bucket [{}]...", bucketName); ListObjectsRequest listObjectsRequest = new ListObjectsRequest(); listObjectsRequest.setBucketName(bucketName); listObjectsRequest.setPrefix(getConfiguration().getPrefix()); if (maxMessagesPerPoll > 0) { listObjectsRequest.setMaxKeys(maxMessagesPerPoll); } // if there was a marker from previous poll then use that to continue from where we left last time if (marker != null) { LOG.trace("Resuming from marker: {}", marker); listObjectsRequest.setMarker(marker); } ObjectListing listObjects = getAmazonS3Client().listObjects(listObjectsRequest); if (listObjects.isTruncated()) { marker = listObjects.getNextMarker(); LOG.trace("Returned list is truncated, so setting next marker: {}", marker); } else { // no more data so clear marker marker = null; } if (LOG.isTraceEnabled()) { LOG.trace("Found {} objects in bucket [{}]...", listObjects.getObjectSummaries().size(), bucketName); } exchanges = createExchanges(listObjects.getObjectSummaries()); } return processBatch(CastUtils.cast(exchanges)); }
From source file:io.milton.s3.AmazonS3ManagerImpl.java
License:Open Source License
@Override public List<S3ObjectSummary> findEntityByBucket(String bucketName) { LOG.info("Returns a list of summary information about the objects in the specified buckets " + bucketName); List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>(); ObjectListing objectListing; try {// w w w .j av a 2 s . c o m do { objectListing = amazonS3Client.listObjects(bucketName); for (final S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { objectSummaries.add(objectSummary); } objectListing = amazonS3Client.listNextBatchOfObjects(objectListing); } while (objectListing.isTruncated()); } catch (AmazonServiceException ase) { LOG.error("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason.", ase); } catch (AmazonClientException ace) { LOG.error("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to communicate" + " with S3, " + "such as not being able to access the network.", ace); } return objectSummaries; }
From source file:io.milton.s3.AmazonS3ManagerImpl.java
License:Open Source License
@Override public List<S3ObjectSummary> findEntityByPrefixKey(String bucketName, String prefixKey) { LOG.info("Returns a list of summary information about the objects in the specified bucket " + bucketName + " for the prefix " + prefixKey); List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>(); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName) .withPrefix(prefixKey);/* w w w .j av a 2 s . c o m*/ ObjectListing objectListing; try { do { objectListing = amazonS3Client.listObjects(listObjectsRequest); for (final S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { objectSummaries.add(objectSummary); } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); LOG.info("Found " + objectSummaries.size() + " objects in the specified bucket " + bucketName + " for the prefix " + prefixKey); } catch (AmazonServiceException ase) { LOG.error("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason.", ase); } catch (AmazonClientException ace) { LOG.error("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to communicate" + " with S3, " + "such as not being able to access the network.", ace); } return objectSummaries; }
From source file:Java21.S3Files.java
License:Open Source License
public static void main(String[] args) throws IOException { /*//from w w w .j a v a 2 s. c om * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); String bucketName = "msm-gb-env-etl-iq/dev1-dwh/" + UUID.randomUUID(); //String key = ""; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); /* * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); }
From source file:javafxawss3sample.FXMLDocumentController.java
@Override public void initialize(URL url, ResourceBundle rb) { AmazonS3 s3 = new AmazonS3Client(); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2);//from w ww .j a v a 2 s.c om System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("==========================================="); s3.listBuckets().forEach(bucket -> { // creating tab for each bucket Tab tab = new Tab(); String bucketNm = bucket.getName(); tab.setText(bucketNm); tabPane.getTabs().add(tab); VBox vbox = new VBox(10); vbox.setPadding(new Insets(10)); vbox.setStyle("-fx-background-color: #ffc9ae"); // Owner HBox hbox1 = new HBox(10); Label ownerLabel = new Label("Owner:"); String owner = bucket.getOwner().getDisplayName(); Text ownerText = new Text(owner); hbox1.getChildren().addAll(ownerLabel, ownerText); // Create Date HBox hbox2 = new HBox(10); Label dateLabel = new Label("Create Date:"); String createDate = bucket.getCreationDate().toString(); Text dateText = new Text(createDate); hbox2.getChildren().addAll(dateLabel, dateText); tab.setContent(vbox); tab.setStyle("-fx-background-color: #ffc9ae;"); // ListView for file path ObservableList<String> items = FXCollections.observableArrayList("file path"); ListView view = new ListView(items); ObjectListing objList = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketNm).withPrefix("")); objList.getObjectSummaries().forEach(obj -> { String filePath = obj.getKey(); items.add(filePath); }); vbox.getChildren().addAll(hbox1, hbox2, view); }); }
From source file:jenkins.plugins.itemstorage.s3.S3DownloadAllCallable.java
License:Open Source License
/** * Download to executor// w w w .j av a 2 s. co m */ @Override public Integer invoke(TransferManager transferManager, File base, VirtualChannel channel) throws IOException, InterruptedException { if (!base.exists()) { if (!base.mkdirs()) { throw new IOException("Failed to create directory : " + base); } } int totalCount; Downloads downloads = new Downloads(); ObjectListing objectListing = null; do { objectListing = transferManager.getAmazonS3Client() .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix(pathPrefix) .withMarker(objectListing != null ? objectListing.getNextMarker() : null)); for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { downloads.startDownload(transferManager, base, pathPrefix, summary); } } while (objectListing.getNextMarker() != null); // Grab # of files copied totalCount = downloads.count(); // Finish the asynchronous downloading process downloads.finishDownloading(); return totalCount; }
From source file:jenkins.plugins.itemstorage.s3.S3Profile.java
License:Open Source License
public boolean exists(String bucketName, String path) { ObjectListing objectListing = helper.client() .listObjects(new ListObjectsRequest(bucketName, path, null, null, 1)); return !objectListing.getObjectSummaries().isEmpty(); }
From source file:jenkins.plugins.itemstorage.s3.S3Profile.java
License:Open Source License
public void delete(String bucketName, String pathPrefix) { ObjectListing listing = null; do {/*from w w w . jav a2 s . c om*/ listing = listing == null ? helper.client().listObjects(bucketName, pathPrefix) : helper.client().listNextBatchOfObjects(listing); DeleteObjectsRequest req = new DeleteObjectsRequest(bucketName); List<DeleteObjectsRequest.KeyVersion> keys = new ArrayList<>(listing.getObjectSummaries().size()); for (S3ObjectSummary summary : listing.getObjectSummaries()) { keys.add(new DeleteObjectsRequest.KeyVersion(summary.getKey())); } req.withKeys(keys); helper.client().deleteObjects(req); } while (listing.isTruncated()); }
From source file:jenkins.plugins.itemstorage.s3.S3Profile.java
License:Open Source License
public void rename(String bucketName, String currentPathPrefix, String newPathPrefix) { ObjectListing listing = null; do {/*from www.j av a 2 s .c om*/ listing = listing == null ? helper.client().listObjects(bucketName, currentPathPrefix) : helper.client().listNextBatchOfObjects(listing); for (S3ObjectSummary summary : listing.getObjectSummaries()) { String key = summary.getKey(); helper.client().copyObject(bucketName, key, bucketName, newPathPrefix + key.substring(currentPathPrefix.length())); helper.client().deleteObject(bucketName, key); } } while (listing.isTruncated()); }