Search in sources :

Example 1 with S3Object

use of com.emc.object.s3.bean.S3Object in project pravega by pravega.

the class S3FileSystemImpl method listObjects.

@Override
public ListObjectsResult listObjects(String bucketName, String prefix) {
    ListObjectsResult result = new ListObjectsResult();
    ArrayList<S3Object> list = new ArrayList<>();
    Path path = Paths.get(this.baseDir, bucketName, prefix);
    try {
        if (Files.exists(path)) {
            if (Files.isDirectory(path)) {
                Files.list(path).forEach(file -> {
                    addFileAsObjectToList(file, list, bucketName);
                });
            } else {
                addFileAsObjectToList(path, list, bucketName);
            }
        }
    } catch (IOException e) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    result.setObjects(list);
    return result;
}
Also used : Path(java.nio.file.Path) S3Exception(com.emc.object.s3.S3Exception) ArrayList(java.util.ArrayList) S3Object(com.emc.object.s3.bean.S3Object) IOException(java.io.IOException) ListObjectsResult(com.emc.object.s3.bean.ListObjectsResult)

Example 2 with S3Object

use of com.emc.object.s3.bean.S3Object in project pravega by pravega.

the class S3FileSystemImpl method addFileAsObjectToList.

// Adds a single file to the list as an object.
private void addFileAsObjectToList(Path path, ArrayList<S3Object> list, String bucketName) {
    S3Object object = new S3Object();
    object.setKey(path.toString().replaceFirst(Paths.get(this.baseDir, bucketName).toString(), ""));
    list.add(object);
}
Also used : S3Object(com.emc.object.s3.bean.S3Object)

Aggregations

S3Object (com.emc.object.s3.bean.S3Object)2 S3Exception (com.emc.object.s3.S3Exception)1 ListObjectsResult (com.emc.object.s3.bean.ListObjectsResult)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1