Example usage for com.amazonaws.services.s3.model S3ObjectSummary getLastModified

List of usage examples for com.amazonaws.services.s3.model S3ObjectSummary getLastModified

Introduction

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

Prototype

public Date getLastModified() 

Source Link

Document

Gets the date when, according to Amazon S3, this object was last modified.

Usage

From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3Backend.java

License:Apache License

public List<DataRecord> getAllMetadataRecords(String prefix) {
    List<DataRecord> metadataList = new ArrayList<DataRecord>();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {//  w  w  w. ja  va2s  . c  om
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket)
                .withPrefix(addMetaKeyPrefix(prefix));
        ObjectListing prevObjectListing = s3service.listObjects(listObjectsRequest);
        for (final S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
            metadataList.add(new S3DataRecord(s3service, bucket, stripMetaKeyPrefix(s3ObjSumm.getKey()),
                    s3ObjSumm.getLastModified().getTime(), s3ObjSumm.getSize()));
        }
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
    return metadataList;
}

From source file:org.apache.jackrabbit.oak.blob.cloud.aws.s3.S3Backend.java

License:Apache License

@Override
public Iterator<DataRecord> getAllRecords() {
    return new RecordsIterator<DataRecord>(new Function<S3ObjectSummary, DataRecord>() {
        @Override//from  ww  w. ja v  a2s . com
        public DataRecord apply(S3ObjectSummary input) {
            return new S3DataRecord(s3service, bucket, getIdentifierName(input.getKey()),
                    input.getLastModified().getTime(), input.getSize());
        }
    });
}

From source file:org.entando.entando.plugins.jps3awsclient.aps.system.services.storage.AmazonS3StorageManager.java

License:Open Source License

private BasicFileAttributeView[] listAttributes(String subPath, boolean isProtectedResource, boolean addFolders,
        boolean addFiles) throws ApsSystemException {
    if (!this.isActive()) {
        return null;
    }/*from   ww  w .ja  va 2s  .c o  m*/
    String folder = this.getKey(subPath, isProtectedResource);
    ObjectListing objectListing = this.getS3Objects(folder);
    if (null == objectListing) {
        return null;
    }
    BasicFileAttributeView[] objects = new BasicFileAttributeView[] {};
    if (null != objectListing.getCommonPrefixes() && addFolders) {
        for (int i = 0; i < objectListing.getCommonPrefixes().size(); i++) {
            String object = objectListing.getCommonPrefixes().get(i);
            String name = object.substring(folder.length(), (object.length() - 1));
            BasicFileAttributeView bfav = new BasicFileAttributeView();
            bfav.setDirectory(true);
            bfav.setName(name);
            objects = this.addChildAttribute(bfav, objects);
        }
    }
    if (null != objectListing.getObjectSummaries() && addFiles) {
        for (int i = 0; i < objectListing.getObjectSummaries().size(); i++) {
            S3ObjectSummary s3os = objectListing.getObjectSummaries().get(i);
            String key = s3os.getKey();
            String name = key.substring(folder.length());
            BasicFileAttributeView bfav = new BasicFileAttributeView();
            bfav.setDirectory(false);
            bfav.setName(name);
            bfav.setLastModifiedTime(s3os.getLastModified());
            bfav.setSize(s3os.getSize());
            objects = this.addChildAttribute(bfav, objects);
        }
    }
    return objects;
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserController.java

License:Apache License

@RequestMapping(value = "listObjects", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)/*ww  w  .j  a v  a 2  s . co  m*/
public Response listObjects(@RequestParam(required = false) String bucketName,
        @RequestParam(required = false) String prefix,
        @RequestParam(required = false) String continuationToken) {
    // Get bucket list
    if (StringUtils.isEmpty(bucketName)) {
        Response response = new Response();
        response.getList().addAll(getBucketList());
        response.setSuccess(true);
        return response;
    }

    // Get folder & bucket list
    ListObjectsV2Result result = s3BrowserService.listObjects(bucketName, prefix, continuationToken);

    List<S3ObjectInfo> list = new ArrayList<>();
    List<String> commonPrefixes = result.getCommonPrefixes();
    for (String key : commonPrefixes) {
        S3ObjectInfo object = new S3ObjectInfo();
        object.setBucketName(bucketName);
        object.setKey(key);
        object.setName(getName(key));
        object.setFolder(true);
        list.add(object);
    }

    List<S3ObjectSummary> objectSummaries = result.getObjectSummaries();

    if (!StringUtils.endsWith(prefix, S3Constansts.DELIMITER)) {
        prefix = prefix + S3Constansts.DELIMITER;
    }
    for (S3ObjectSummary s3Object : objectSummaries) {
        String key = s3Object.getKey();
        if (prefix.equals(key)) {
            continue;
        }
        S3ObjectInfo object = new S3ObjectInfo();
        object.setBucketName(bucketName);
        object.setPrefix(prefix);
        object.setKey(key);
        object.setName(getName(key));
        object.setObject(true);
        object.setSize(s3Object.getSize());
        object.setLastModified(s3Object.getLastModified());
        object.setStorageClass(s3Object.getStorageClass());
        list.add(object);
    }

    Map<String, String> map = new HashMap<>();
    map.put(S3Constansts.CONTINUATIONTOKEN, result.getNextContinuationToken());
    map.put(S3Constansts.ISTRUNCATED, BooleanUtils.toStringTrueFalse(result.isTruncated()));

    Response response = new Response();
    response.getList().addAll(list);
    response.getMap().putAll(map);
    response.setSuccess(true);
    return response;
}

From source file:org.icgc.dcc.storage.server.repository.s3.S3ListingService.java

License:Open Source License

private ObjectInfo createInfo(S3ObjectSummary objectSummary) {
    return new ObjectInfo(getObjectId(objectSummary), objectSummary.getLastModified().getTime(),
            objectSummary.getSize());/*from  ww  w. ja v  a  2 s  .c  o m*/
}

From source file:org.onebusaway.admin.service.impl.S3FileServiceImpl.java

License:Apache License

@Override
/**//from   w ww  . j a v  a  2s  .c  o m
 * Return tabular data (filename, flag, modified date) about bundle directories.
 */
public List<String[]> listBundleDirectories(int maxResults) {
    List<String[]> rows = new ArrayList<String[]>();
    HashMap<String, String> map = new HashMap<String, String>();
    ListObjectsRequest request = new ListObjectsRequest(_bucketName, null, null, "/", maxResults);

    ObjectListing listing = null;
    do {
        if (listing == null) {
            listing = _s3.listObjects(request);
            if (listing.getCommonPrefixes() != null) {
                // short circuit if common prefixes works
                List<String> commonPrefixes = listing.getCommonPrefixes();
                for (String key : commonPrefixes) {
                    Date lastModified = getLastModifiedTimeForKey(key);
                    String lastModifiedStr = "n/a";
                    if (lastModified != null) {
                        lastModifiedStr = "" + lastModified.toString();
                    }
                    String[] columns = { parseKey(key), getStatus(key), lastModifiedStr };
                    rows.add(columns);
                }
                return rows;
            }
            _log.error("prefixes=" + listing.getCommonPrefixes());
        } else {
            listing = _s3.listNextBatchOfObjects(listing);
        }
        for (S3ObjectSummary summary : listing.getObjectSummaries()) {
            String key = parseKey(summary.getKey());
            if (!map.containsKey(key)) {
                String[] columns = { key, " ", "" + summary.getLastModified().getTime() };
                rows.add(columns);
                map.put(key, key);
            }
        }

    } while (listing.isTruncated());
    return rows;
}

From source file:org.openflamingo.fs.s3.S3ObjectProvider.java

License:Apache License

public List<FileInfo> getFiles(String path) {
    String bucket = null;//  w  w w  .j  a  v  a 2 s .  co m

    if (!"/".equals(path)) {
        bucket = S3Utils.getBucket(path + "/");
    }

    String relativePath = S3Utils.getObjectKey(path);

    List<FileInfo> filesList = new ArrayList<FileInfo>();
    if ("".equals(relativePath)) {
        return filesList;
    }

    try {
        ObjectListing objectListing = awsClient.listObjects(
                new ListObjectsRequest().withBucketName(bucket).withPrefix(relativePath).withDelimiter("/"));

        while (true) {
            List<S3ObjectSummary> summaries = objectListing.getObjectSummaries();
            for (S3ObjectSummary objectSummary : summaries) {
                if (!objectSummary.getKey().endsWith("/")) {
                    long size = objectSummary.getSize();
                    String filename = FileUtils.getFilename(objectSummary.getKey());
                    String bucketName = objectSummary.getBucketName();
                    long modified = objectSummary.getLastModified().getTime();
                    S3ObjectInfo info = new S3ObjectInfo(bucketName, objectSummary.getKey(), filename, modified,
                            size);
                    filesList.add(info);
                }
            }

            if (!objectListing.isTruncated()) {
                break;
            }
            objectListing = awsClient.listNextBatchOfObjects(objectListing);

        }

        return filesList;
    } catch (Exception ase) {
        //            throw new FileSystemException("? ? ? ? ? ?.", ase);
        throw new FileSystemException("An error has occurred.", ase);
    }
}

From source file:org.springframework.integration.aws.inbound.S3InboundFileSynchronizer.java

License:Apache License

@Override
protected long getModified(S3ObjectSummary file) {
    return file.getLastModified().getTime();
}

From source file:org.springframework.integration.aws.s3.core.AmazonS3OperationsImpl.java

License:Apache License

public PaginatedObjectsView listObjects(String bucketName, String folder, String nextMarker, int pageSize) {
    if (logger.isDebugEnabled()) {
        logger.debug("Listing objects from bucket " + bucketName + " and folder " + folder);
        logger.debug("Next marker is " + nextMarker + " and pageSize is " + pageSize);
    }// w w  w  . j a  v a 2  s  . c  om

    Assert.notNull(StringUtils.hasText(bucketName), "Bucket name should be non null and non empty");
    String prefix = null;
    if (folder != null && !"/".equals(folder)) {
        prefix = folder;
    }
    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
            .withPrefix(prefix).withMarker(nextMarker);

    if (pageSize > 0) {
        listObjectsRequest.withMaxKeys(pageSize);
    }

    ObjectListing listing = client.listObjects(listObjectsRequest);
    PaginatedObjectsView view = null;
    List<com.amazonaws.services.s3.model.S3ObjectSummary> summaries = listing.getObjectSummaries();
    if (summaries != null && !summaries.isEmpty()) {
        List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>();
        for (final com.amazonaws.services.s3.model.S3ObjectSummary summary : summaries) {
            S3ObjectSummary summ = new S3ObjectSummary() {

                public long getSize() {
                    return summary.getSize();
                }

                public Date getLastModified() {
                    return summary.getLastModified();
                }

                public String getKey() {
                    return summary.getKey();
                }

                public String getETag() {
                    return summary.getETag();
                }

                public String getBucketName() {
                    return summary.getBucketName();
                }
            };
            objectSummaries.add(summ);
        }
        view = new PagninatedObjectsViewImpl(objectSummaries, listing.getNextMarker());
    }
    return view;
}

From source file:org.springframework.integration.aws.s3.core.DefaultAmazonS3Operations.java

License:Apache License

/**
 * The implementation that uses the AWS SDK to list objects from the given bucket
 *
 * @param bucketName The bucket in which we want to list the objects in
 * @param nextMarker The number of objects can be very large and this serves as the marker
 *                 for remembering the last record fetch in the last retrieve operation.
 * @param pageSize The max number of records to be retrieved in one list object operation.
 * @param prefix The prefix for the list operation, this can serve as the folder whose contents
 *              are to be listed.//from  w  w w  . j ava 2 s.com
 */
@Override
protected PaginatedObjectsView doListObjects(String bucketName, String nextMarker, int pageSize,
        String prefix) {

    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName)
            .withPrefix(prefix).withMarker(nextMarker);

    if (pageSize > 0) {
        listObjectsRequest.withMaxKeys(pageSize);
    }

    ObjectListing listing = client.listObjects(listObjectsRequest);
    PaginatedObjectsView view = null;
    List<com.amazonaws.services.s3.model.S3ObjectSummary> summaries = listing.getObjectSummaries();
    if (summaries != null && !summaries.isEmpty()) {
        List<S3ObjectSummary> objectSummaries = new ArrayList<S3ObjectSummary>();
        for (final com.amazonaws.services.s3.model.S3ObjectSummary summary : summaries) {
            S3ObjectSummary summ = new S3ObjectSummary() {

                public long getSize() {
                    return summary.getSize();
                }

                public Date getLastModified() {
                    return summary.getLastModified();
                }

                public String getKey() {
                    return summary.getKey();
                }

                public String getETag() {
                    return summary.getETag();
                }

                public String getBucketName() {
                    return summary.getBucketName();
                }
            };
            objectSummaries.add(summ);
        }
        view = new PagninatedObjectsViewImpl(objectSummaries, listing.getNextMarker());
    }
    return view;
}