List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getLastModified
public Date getLastModified()
From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java
License:Apache License
@Override public S3ObjectInfo getObjectProperty(String bucketName, String key) { ObjectMetadata metadata = this.s3.getObjectMetadata(bucketName, key); S3ObjectInfo object = new S3ObjectInfo(); object.setBucketName(bucketName);/*from w w w . j a v a 2 s .co m*/ object.setKey(key); object.setName(getName(key)); object.setLastModified(metadata.getLastModified()); object.setContentType(metadata.getContentType()); object.seteTag(metadata.getETag()); URL url = this.s3.getUrl(bucketName, key); object.setUri(url.toString()); AccessControlList acl = this.s3.getObjectAcl(bucketName, key); object.setOwner(acl.getOwner().getDisplayName()); return object; }
From source file:org.fcrepo.modeshape.binary.S3BinaryStore.java
License:Apache License
@Override public void removeValuesUnusedLongerThan(long minimumAge, TimeUnit timeUnit) throws BinaryStoreException { Date deadline = new Date(System.currentTimeMillis() - timeUnit.toMillis(minimumAge)); // There is no capacity in S3 to query on object properties. This must be done // by straight iteration, so may take a very long time for large data sets. try {/*from www. j a va 2 s.c o m*/ for (BinaryKey key : getAllBinaryKeys()) { ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, key.toString()); String unused = metadata.getUserMetadata().get(UNUSED_KEY); if (null != unused && unused.equals(String.valueOf(true))) { Date lastMod = metadata.getLastModified(); if (lastMod.before(deadline)) { try { s3Client.deleteObject(bucketName, key.toString()); } catch (AmazonClientException e) { Logger log = Logger.getLogger(getClass()); log.warn(e, JcrI18n.unableToDeleteTemporaryFile, e.getMessage()); } } } // Assumes that if no value is set, content is used } } catch (AmazonClientException e) { throw new BinaryStoreException(e); } }
From source file:org.gradle.internal.resource.transport.aws.s3.S3Resource.java
License:Apache License
public ExternalResourceMetaData getMetaData() { ObjectMetadata objectMetadata = s3Object.getObjectMetadata(); Date lastModified = objectMetadata.getLastModified(); return new DefaultExternalResourceMetaData(uri, lastModified.getTime(), getContentLength(), s3Object.getObjectMetadata().getContentType(), s3Object.getObjectMetadata().getETag(), null); // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb) }
From source file:org.gradle.internal.resource.transport.aws.s3.S3ResourceConnector.java
License:Apache License
public ExternalResourceMetaData getMetaData(URI location) { LOGGER.debug("Attempting to get resource metadata: {}", location); S3Object s3Object = s3Client.getMetaData(location); if (s3Object == null) { return null; }/*ww w . j av a 2 s . c o m*/ ObjectMetadata objectMetadata = s3Object.getObjectMetadata(); return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), null); // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb) }
From source file:org.kuali.maven.wagon.S3Wagon.java
License:Educational Community License
/** * Is the S3 object newer than the timestamp passed in? *//*w w w .j a v a 2 s . c om*/ @Override protected boolean isRemoteResourceNewer(final String resourceName, final long timestamp) { ObjectMetadata metadata = client.getObjectMetadata(bucket.getName(), basedir + resourceName); return metadata.getLastModified().compareTo(new Date(timestamp)) < 0; }
From source file:org.openflamingo.fs.s3.S3Utils.java
License:Apache License
/** * Bucket ./*from w w w .j a v a2s .com*/ * * @param client Amazon S3 Client * @param bucketName Bucket Name */ public static Map<String, String> getBucketInfo(AmazonS3Client client, String bucketName) { Bucket bucket = getBucket(client, bucketName); if (bucket == null) { return null; } ObjectMetadata objectMetadata = client.getObjectMetadata(bucketName, ""); Map<String, String> map = new HashMap<String, String>(); map.put("name", bucket.getName()); map.put("ownerName", bucket.getOwner().getDisplayName()); map.put("ownerId", bucket.getOwner().getId()); setValue("create", bucket.getCreationDate(), map); setValue("location", client.getBucketLocation(bucketName), map); setValue("version", objectMetadata.getVersionId(), map); setValue("contentDisposition", objectMetadata.getContentDisposition(), map); setValue("contentType", objectMetadata.getContentType(), map); setValue("etag", objectMetadata.getETag(), map); setValue("contentEncoding", objectMetadata.getContentEncoding(), map); setValue("contentLength", objectMetadata.getContentLength(), map); setValue("lastModified", objectMetadata.getLastModified(), map); return map; }
From source file:org.openflamingo.fs.s3.S3Utils.java
License:Apache License
/** * Object ./* w w w. j a v a 2 s .c om*/ * * @param client Amazon S3 Client * @param bucketName Bucket Name */ public static Map<String, String> getObject(AmazonS3Client client, String bucketName, String objectKey) { S3Object object = client.getObject(bucketName, objectKey); ObjectMetadata objectMetadata = object.getObjectMetadata(); Map<String, String> map = new HashMap<String, String>(); if (!object.getKey().endsWith("/")) { String qualifiedPath = "/" + bucketName + "/" + object.getKey(); map.put("bucketName", object.getBucketName()); map.put("name", FileUtils.getFilename(qualifiedPath)); map.put("path", qualifiedPath); } else { map.put("bucketName", object.getBucketName()); map.put("name", object.getKey()); map.put("name", "/" + bucketName + "/" + object.getKey()); } setValue("redirectionLocation", object.getRedirectLocation(), map); setValue("version", objectMetadata.getVersionId(), map); setValue("contentDisposition", objectMetadata.getContentDisposition(), map); setValue("contentType", objectMetadata.getContentType(), map); setValue("etag", objectMetadata.getETag(), map); setValue("contentEncoding", objectMetadata.getContentEncoding(), map); setValue("contentLength", objectMetadata.getContentLength(), map); setValue("lastModified", objectMetadata.getLastModified(), map); return map; }
From source file:org.openflamingo.fs.s3.S3Utils.java
License:Apache License
/** * Object .//from w ww . j a v a 2 s . c o m * * @param client Amazon S3 Client * @param bucketName Bucket Name */ public static Map<String, String> getDirectory(AmazonS3Client client, String bucketName, String objectKey) { S3Object object = client.getObject(bucketName, objectKey); ObjectMetadata objectMetadata = object.getObjectMetadata(); List<FileInfo> filesList = new ArrayList<FileInfo>(); ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(object.getBucketName()) .withPrefix(objectKey).withDelimiter("/"); ObjectListing objectListing = null; do { objectListing = client.listObjects(listObjectsRequest); List<String> commonPrefixes = objectListing.getCommonPrefixes(); List<S3ObjectSummary> summary = objectListing.getObjectSummaries(); listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); Map<String, String> map = new HashMap<String, String>(); map.put("bucketName", object.getBucketName()); map.put("name", object.getKey()); map.put("redirectionLocation", object.getRedirectLocation()); setValue("version", objectMetadata.getVersionId(), map); setValue("contentDisposition", objectMetadata.getContentDisposition(), map); setValue("contentType", objectMetadata.getContentType(), map); setValue("etag", objectMetadata.getETag(), map); setValue("contentEncoding", objectMetadata.getContentEncoding(), map); setValue("contentLength", objectMetadata.getContentLength(), map); setValue("lastModified", objectMetadata.getLastModified(), map); return null; }
From source file:org.xmlsh.aws.util.AWSS3Command.java
License:BSD License
protected void writeMeta(ObjectMetadata m) throws InvalidArgumentException, XMLStreamException, SaxonApiException { mLogger.entry(m);//from w ww.j a va2s. co m startElement(sMetaDataElem); attribute("cache-control", m.getCacheControl()); attribute("content-disposition", m.getContentDisposition()); attribute("content-encoding", m.getContentEncoding()); attribute("md5", m.getContentMD5()); attribute("etag", m.getETag()); attribute("version-id", m.getVersionId()); attribute("content-length", String.valueOf(m.getContentLength())); attribute("last-modified", Util.formatXSDateTime(m.getLastModified())); attribute("expiration-time", Util.formatXSDateTime(m.getExpirationTime())); attribute("expiration-time-rule-id", m.getExpirationTimeRuleId()); attribute("httpExpiresDate", Util.formatXSDateTime(m.getHttpExpiresDate())); attribute("ongoingRestore", m.getOngoingRestore()); attribute("restore-expiration-time", Util.formatXSDateTime(m.getRestoreExpirationTime())); attribute("instance-length", m.getInstanceLength()); attribute("sse-algorithm", m.getSSEAlgorithm()); attribute("sse-aws-kms-key-id", m.getSSEAwsKmsKeyId()); attribute("sse-customer-algorithm", m.getSSECustomerAlgorithm()); attribute("sse-customer-key-md5", m.getSSECustomerKeyMd5()); attribute("storage-class", m.getStorageClass()); startElement("user-metadata"); for (Entry<String, String> user : m.getUserMetadata().entrySet()) { startElement(sUserMetaDataElem); attribute("name", user.getKey()); attribute("value", user.getValue()); endElement(); } endElement(); endElement(); mLogger.exit(); }