private static long lastModifiedTime(ObjectMetadata metadata) { Date date = metadata.getLastModified(); return (date != null) ? date.getTime() : 0; }
@Override @Nullable protected ObjectStatus getObjectStatus(String key) throws IOException { try { ObjectMetadata meta = mClient.getObjectMetadata(mBucketName, key); return new ObjectStatus(key, meta.getETag(), meta.getContentLength(), meta.getLastModified().getTime()); } catch (AmazonServiceException e) { if (e.getStatusCode() == 404) { // file not found, possible for exists calls return null; } throw new IOException(e); } catch (AmazonClientException e) { throw new IOException(e); } }
@Override public LoadedInstanceConfig storeConfig(ConfigCollection config, long compareVersion) throws Exception { { ObjectMetadata metadata = getConfigMetadata(); if ( metadata != null ) { Date lastModified = metadata.getLastModified(); if ( lastModified.getTime() != compareVersion ) { return null; // apparently there's no atomic way to do this with S3 so this will have to do } } } PropertyBasedInstanceConfig propertyBasedInstanceConfig = new PropertyBasedInstanceConfig(config); ByteArrayOutputStream out = new ByteArrayOutputStream(); propertyBasedInstanceConfig.getProperties().store(out, "Auto-generated by Exhibitor " + hostname); byte[] bytes = out.toByteArray(); ObjectMetadata metadata = S3Utils.simpleUploadFile(s3Client, bytes, arguments.getBucket(), arguments.getKey()); return new LoadedInstanceConfig(propertyBasedInstanceConfig, metadata.getLastModified().getTime()); }
@Override public LoadedInstanceConfig loadConfig() throws Exception { Date lastModified; Properties properties = new Properties(); S3Object object = getConfigObject(); if ( object != null ) { try { lastModified = object.getObjectMetadata().getLastModified(); properties.load(object.getObjectContent()); } finally { CloseableUtils.closeQuietly(object.getObjectContent()); } } else { lastModified = new Date(0L); } PropertyBasedInstanceConfig config = new PropertyBasedInstanceConfig(properties, defaults); return new LoadedInstanceConfig(config, lastModified.getTime()); }
timestampedSegments, dataSegment, objectMetadata.getLastModified() == null ? 0 : objectMetadata.getLastModified().getTime() );
/** * Returns the captured state of the download; or null if it should not be * captured (for security reason). */ private PersistableDownload captureDownloadState( final GetObjectRequest getObjectRequest, final File file) { if (getObjectRequest.getSSECustomerKey() == null) { return new PersistableDownload( getObjectRequest.getBucketName(), getObjectRequest.getKey(), getObjectRequest.getVersionId(), getObjectRequest.getRange(), getObjectRequest.getResponseHeaders(), getObjectRequest.isRequesterPays(), file.getAbsolutePath(), getLastFullyDownloadedPartNumber(), getObjectMetadata().getLastModified().getTime(), getLastFullyDownloadedFilePosition()); } return null; }
long lastModifiedTime = objectMetadata.getLastModified().getTime();
private static long lastModifiedTime(ObjectMetadata metadata) { Date date = metadata.getLastModified(); return (date != null) ? date.getTime() : 0; }
private static long lastModifiedTime(ObjectMetadata metadata) { Date date = metadata.getLastModified(); return (date != null) ? date.getTime() : 0; }
/** * Is the S3 object newer than the timestamp passed in? */ @Override protected boolean isRemoteResourceNewer(final String resourceName, final long timestamp) { ObjectMetadata metadata = client.getObjectMetadata(bucketName, basedir + resourceName); return metadata.getLastModified().compareTo(new Date(timestamp)) < 0; }
@Override public Date lastModified() { return new Date( this.object.getObjectMetadata().getLastModified().getTime() ); }
@Override public long lastModified() throws IOException { return getRequiredObjectMetadata().getLastModified().getTime(); }
@Override public long lastModified() throws IOException { return getRequiredObjectMetadata().getLastModified().getTime(); }
@Override protected boolean isRemoteResourceNewer(String resourceName, long timestamp) throws ResourceDoesNotExistException { try { Date lastModified = getObjectMetadata(resourceName).getLastModified(); return lastModified == null || lastModified.getTime() > timestamp; } catch (AmazonServiceException e) { throw new ResourceDoesNotExistException(String.format("'%s' does not exist", resourceName), e); } }
@Override protected boolean isRemoteResourceNewer(String resourceName, long timestamp) throws ResourceDoesNotExistException { try { Date lastModified = getObjectMetadata(resourceName).getLastModified(); return lastModified == null ? true : lastModified.getTime() > timestamp; } catch (AmazonServiceException e) { throw new ResourceDoesNotExistException(String.format("'%s' does not exist", resourceName), e); } }
@Override protected boolean isRemoteResourceNewer(String resourceName, long timestamp) throws ResourceDoesNotExistException { try { Date lastModified = getObjectMetadata(resourceName).getLastModified(); return lastModified == null || lastModified.getTime() > timestamp; } catch (AmazonServiceException e) { throw new ResourceDoesNotExistException(String.format("'%s' does not exist", resourceName), e); } }
assertNull(om.getRawMetadataValue(Headers.EXTENDED_REQUEST_ID)); assertEquals(om.getUserMetaDataOf("userKey"), "userValue"); assertEquals(1136116800000L, om.getLastModified().getTime()); assertEquals(om.getContentLength(), 5); assertEquals(om.getETag(), "Etag");
assertEquals(om.getRawMetadataValue(Headers.EXTENDED_REQUEST_ID), null); assertEquals(om.getUserMetaDataOf("userKey"), "userValue"); assertEquals(1136116800000L, om.getLastModified().getTime()); assertEquals(om.getContentLength(), 5); assertEquals(om.getETag(), "Etag");
assertEquals(lastModified, from.getLastModified()); assertNotSame(lastModified, from.getLastModified()); assertEquals(httpExpiresDate, to.getHttpExpiresDate()); assertTrue(9999 == to.getInstanceLength()); assertEquals(lastModified, to.getLastModified()); assertTrue(to.getOngoingRestore());
@Test public void cloneEmpty() { ObjectMetadata from = new ObjectMetadata(); for (int i = 0; i < 2; i++) { assertNull(from.getCacheControl()); assertNull(from.getContentDisposition()); assertNull(from.getContentEncoding()); assertTrue(0 == from.getContentLength()); assertNull(from.getContentMD5()); assertNull(from.getContentType()); assertNull(from.getETag()); assertNull(from.getExpirationTime()); assertNull(from.getExpirationTimeRuleId()); assertNull(from.getHttpExpiresDate()); assertTrue(0 == from.getInstanceLength()); assertNull(from.getLastModified()); assertNull(from.getOngoingRestore()); assertTrue(from.getRawMetadata().size() == 0); assertNull(from.getRestoreExpirationTime()); assertNull(from.getSSEAlgorithm()); assertNull(from.getSSECustomerAlgorithm()); assertNull(from.getSSECustomerKeyMd5()); assertTrue(0 == from.getUserMetadata().size()); assertNull(from.getVersionId()); assertNull(from.getStorageClass()); // Clone an empty instance from = from.clone(); } }