Example usage for com.amazonaws.services.s3.model ObjectListing getObjectSummaries

List of usage examples for com.amazonaws.services.s3.model ObjectListing getObjectSummaries

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model ObjectListing getObjectSummaries.

Prototype

public List<S3ObjectSummary> getObjectSummaries() 

Source Link

Document

Gets the list of object summaries describing the objects stored in the S3 bucket.

Usage

From source file:ch.admin.isb.hermes5.persistence.s3.S3RemoteAdapter.java

License:Apache License

@Override
public List<String> listFiles(String path) {
    ObjectListing listObjects = s3.listObjects(this.bucketName.getStringValue(), path);
    List<S3ObjectSummary> objectSummaries = listObjects.getObjectSummaries();
    List<String> files = new ArrayList<String>();
    for (S3ObjectSummary s3ObjectSummary : objectSummaries) {
        String key = s3ObjectSummary.getKey();
        files.add(key.substring(path.length() + 1));
    }/*from  w w w.  ja  va 2 s.  co  m*/
    return files;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String listBucketContents(String access_key, String secret_key, String bucket, String endpoint) {
    objectlist = null;//from  w  ww . java 2 s  .  co m

    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);

    try {
        ObjectListing current = s3Client.listObjects((bucket));

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket);
        ObjectListing objectListing;
        do {
            objectListing = s3Client.listObjects(listObjectsRequest);
            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                objectlist = objectlist + "@@" + objectSummary.getKey();
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

    } catch (Exception listBucket) {
        mainFrame.jTextArea1.append("\n" + listBucket.getMessage());
    }

    String parse = null;
    if (objectlist != null) {
        parse = objectlist;
    } else {
        parse = "No objects_found.";
    }
    return parse;
}

From source file:cloudExplorer.BucketClass.java

License:Open Source License

String getObjectInfo(String key, String access_key, String secret_key, String bucket, String endpoint,
        String process) {/*from  www. j a v a 2  s.  c om*/
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration().withSignerOverride("S3SignerType"));
    s3Client.setEndpoint(endpoint);
    objectlist = null;

    try {
        ObjectListing current = s3Client.listObjects((bucket));

        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket);
        ObjectListing objectListing;
        do {
            objectListing = s3Client.listObjects(listObjectsRequest);

            for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {

                if (process.contains("objectsize")) {
                    if (objectSummary.getKey().contains(key)) {
                        objectlist = String.valueOf(objectSummary.getSize());
                        break;
                    }
                }

                if (process.contains("objectdate")) {
                    if (objectSummary.getKey().contains(key)) {
                        objectlist = String.valueOf(objectSummary.getLastModified());
                        break;
                    }

                }
            }
            listObjectsRequest.setMarker(objectListing.getNextMarker());
        } while (objectListing.isTruncated());

    } catch (Exception listBucket) {
        mainFrame.jTextArea1.append("\n" + listBucket.getMessage());
    }

    return objectlist;
}

From source file:cloudtrailviewer.components.S3FileChooserDialog.java

License:Open Source License

private void reloadContents() {

    List<String> tmp = new ArrayList<String>();
    this.files.setAll(tmp);

    String bucketName = PropertiesSingleton.getInstance().getProperty("Bucket");

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
    listObjectsRequest.setBucketName(bucketName);
    listObjectsRequest.setPrefix(prefix);
    listObjectsRequest.setDelimiter("/");

    AWSCredentials credentials = new BasicAWSCredentials(PropertiesSingleton.getInstance().getProperty("Key"),
            PropertiesSingleton.getInstance().getProperty("Secret"));

    AmazonS3 s3Client = new AmazonS3Client(credentials);

    ObjectListing objectListing = s3Client.listObjects(listObjectsRequest);

    // these are directories
    List<String> directories = objectListing.getCommonPrefixes();
    for (String directory : directories) {

        tmp.add(stripPrefix(directory));
    }/*from   ww  w  .j a  va2 s  .  c o m*/

    // these are files
    List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
    for (final S3ObjectSummary objectSummary : objectSummaries) {

        tmp.add(stripPrefix(objectSummary.getKey()));
    }

    this.files.setAll(tmp);
}

From source file:com.adobe.acs.commons.mcp.impl.processes.asset.S3AssetIngestor.java

License:Apache License

private void createFolders(ActionManager manager, ObjectListing listing) {
    listing.getObjectSummaries().stream().filter(sum -> !sum.getKey().equals(s3BasePath))
            .map(S3HierarchicalElement::new).filter(S3HierarchicalElement::isFolder)
            .filter(this::canImportFolder).forEach(el -> {
                manager.deferredWithResolver(Actions.retry(retries, retryPause, rr -> {
                    manager.setCurrentItem(el.getItemName());
                    createFolderNode(el, rr);
                }));/*w ww.j ava2 s  .c om*/
            });
    if (listing.isTruncated()) {
        createFolders(manager, s3Client.listNextBatchOfObjects(listing));
    }
}

From source file:com.adobe.acs.commons.mcp.impl.processes.asset.S3AssetIngestor.java

License:Apache License

private void importAssets(ActionManager manager, ObjectListing listing) {
    listing.getObjectSummaries().stream().map(S3HierarchicalElement::new).filter(S3HierarchicalElement::isFile)
            .filter(this::canImportContainingFolder).map(S3HierarchicalElement::getSource).forEach(ss -> {
                try {
                    if (canImportFile(ss)) {
                        manager.deferredWithResolver(
                                Actions.retry(retries, retryPause, importAsset(ss, manager)));
                    } else {
                        incrementCount(skippedFiles, 1);
                        trackDetailedActivity(ss.getName(), "Skip", "Skipping file", 0L);
                    }/*from  ww  w . j  a va2 s .c  o  m*/
                } catch (IOException ex) {
                    Failure failure = new Failure();
                    failure.setException(ex);
                    failure.setNodePath(ss.getElement().getNodePath(preserveFileName));
                    manager.getFailureList().add(failure);
                } finally {
                    try {
                        ss.close();
                    } catch (IOException ex) {
                        Failure failure = new Failure();
                        failure.setException(ex);
                        failure.setNodePath(ss.getElement().getNodePath(preserveFileName));
                        manager.getFailureList().add(failure);
                    }
                }
            });
    if (listing.isTruncated()) {
        importAssets(manager, s3Client.listNextBatchOfObjects(listing));
    }
}

From source file:com.adobe.acs.commons.mcp.impl.processes.S3AssetIngestor.java

License:Apache License

private void createFolders(ActionManager manager, ObjectListing listing) {
    listing.getObjectSummaries().stream().filter(sum -> !sum.getKey().equals(s3BasePath))
            .map(S3HierarchialElement::new).filter(S3HierarchialElement::isFolder).filter(this::canImportFolder)
            .forEach(el -> {/*from ww  w  .j a  va 2  s .  c  om*/
                manager.deferredWithResolver(Actions.retry(10, 100, rr -> {
                    manager.setCurrentItem(el.getItemName());
                    createFolderNode(el, rr);
                }));
            });
    if (listing.isTruncated()) {
        createFolders(manager, s3Client.listNextBatchOfObjects(listing));
    }
}

From source file:com.adobe.acs.commons.mcp.impl.processes.S3AssetIngestor.java

License:Apache License

private void importAssets(ActionManager manager, ObjectListing listing) {
    listing.getObjectSummaries().stream().map(S3HierarchialElement::new).filter(S3HierarchialElement::isFile)
            .filter(this::canImportContainingFolder).map(S3HierarchialElement::getSource).forEach(ss -> {
                if (canImportFile(ss)) {
                    manager.deferredWithResolver(Actions.retry(5, 25, importAsset(ss, manager)));
                } else {
                    filesSkipped.incrementAndGet();
                }/*w  w w .  j  a v  a  2s. c o  m*/
            });
    if (listing.isTruncated()) {
        createFolders(manager, s3Client.listNextBatchOfObjects(listing));
    }
}

From source file:com.aegeus.aws.SimpleStorageService.java

License:Apache License

/**
 * List all files under the current directory based on bucket and prefix parameters
 *
 * @param bucket Bucket name/*from w  w w  . j a  va 2s .  c o m*/
 * @param prefix Prefix name
 * @return File list
 */
public List<S3ObjectSummary> listObjects(String bucket, String prefix) {
    ListObjectsRequest request = new ListObjectsRequest().withBucketName(bucket);
    if (prefix != null) {
        request.setPrefix(prefix);
    }
    List<S3ObjectSummary> summaries = new ArrayList<>();
    ObjectListing listing;

    do {
        listing = s3.listObjects(request);
        summaries.addAll(listing.getObjectSummaries());
        request.setMarker(listing.getNextMarker());
    } while (listing.isTruncated());

    return summaries;
}

From source file:com.ALC.SC2BOAserver.aws.S3StorageManager.java

License:Open Source License

/**
 * Deletes the specified S3 object from the S3 storage service.  If a
 * storage path is passed in that has child S3 objects, it will recursively
 * delete the underlying objects./*from  w  ww. ja v a2 s  .c  o  m*/
 * @param s3Store the s3 object to be deleted
 */
public void delete(SC2BOAStorageObject s3Store) {

    if (s3Store.getStoragePath() == null || s3Store.getStoragePath().equals("")) {
        logger.log(Level.WARNING, "Empty storage path passed to delete method");
        return; // We don't want to delete everything in a path
    }

    // Go through the store structure and delete child objects
    ObjectListing listing = s3Client.listObjects(s3Store.getBucketName(), s3Store.getStoragePath());
    while (true) {
        List<S3ObjectSummary> objectList = listing.getObjectSummaries();
        for (S3ObjectSummary summary : objectList) {
            s3Client.deleteObject(s3Store.getBucketName(), summary.getKey());
        }
        if (listing.isTruncated()) {
            listing = s3Client.listNextBatchOfObjects(listing);
        } else {
            break;
        }
    }

}