Example usage for com.amazonaws.services.s3.model ListObjectsRequest withDelimiter

List of usage examples for com.amazonaws.services.s3.model ListObjectsRequest withDelimiter

Introduction

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

Prototype

public ListObjectsRequest withDelimiter(String delimiter) 

Source Link

Document

Sets the optional delimiter parameter that causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the ObjectListing#getCommonPrefixes() list.

Usage

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.AwsInfiniteFile.java

License:Open Source License

@Override
public InfiniteFile[] listFiles(Date optionalFilterDate, int maxDocs) {
    InfiniteFile[] fileList = null;/*  ww  w .  j a va  2 s. co m*/
    ObjectListing list = null;
    _overwriteTime = 0L;
    ListObjectsRequest listRequest = new ListObjectsRequest().withBucketName(_awsBucketName);
    if (null != _awsObjectName) {
        listRequest.withPrefix(_awsObjectName);
    }
    listRequest.withDelimiter("/");
    list = ((AmazonS3Client) _awsClient).listObjects(listRequest);
    fileList = new InfiniteFile[list.getObjectSummaries().size() + list.getCommonPrefixes().size()];
    //TESTED (3.2)
    int nAdded = 0;
    // Get the sub-directories
    for (String subDir : list.getCommonPrefixes()) {
        // Create directories:
        fileList[nAdded] = new AwsInfiniteFile(_awsBucketName, subDir, null, _awsClient);
        nAdded++;
    } //TESTED (3b.3)
      // Get the files:
    for (S3ObjectSummary s3Obj : list.getObjectSummaries()) {
        if (!s3Obj.getKey().endsWith("/")) {
            fileList[nAdded] = new AwsInfiniteFile(s3Obj.getBucketName(), s3Obj.getKey(),
                    s3Obj.getLastModified(), _awsClient);
            long fileTime = fileList[nAdded].getDate();
            if (fileTime > _overwriteTime) {
                _overwriteTime = fileTime;
            } //TESTED (3.2)
            nAdded++;
        }
    }
    return fileList;
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java

License:Apache License

/**
 * Lists the children of this file.  Is only called if {@link #doGetType}
 * returns {@link FileType#FOLDER}.  The return value of this method
 * is cached, so the implementation can be expensive.<br />
 * @return a possible empty String array if the file is a directory or null or an exception if the
 * file is not a directory or can't be read.
 * @throws Exception if an error occurs.
 */// ww w .  ja  v  a  2s  .  c  om
@Override
protected String[] doListChildren() throws Exception {
    String[] res = null;

    Pair<String, String> path = getContainerAndPath();

    String prefix = path.getRight();
    if (prefix.endsWith("/") == false) {
        // We need folders ( prefixes ) to end with a slash
        prefix += "/";
    }
    ListObjectsRequest loReq = new ListObjectsRequest();
    loReq.withBucketName(path.getLeft());
    loReq.withPrefix(prefix);
    loReq.withDelimiter("/");

    ObjectListing blobs = fileSystem.getClient().listObjects(loReq);

    List<String> resList = new ArrayList<>();
    for (S3ObjectSummary osum : blobs.getObjectSummaries()) {
        String currBlobStr = osum.getKey();
        resList.add(String.format("/%s/%s", path.getLeft(), currBlobStr));
    }

    List<String> commPrefixes = blobs.getCommonPrefixes();
    if (commPrefixes != null) {
        for (String currFld : commPrefixes) {
            resList.add(String.format("/%s/%s", path.getLeft(), currFld));
        }
    }

    res = resList.toArray(new String[resList.size()]);

    return res;
}