@Override public ObjectMetadata getObjectMetadata(String bucketName, String key) throws SdkClientException, AmazonServiceException { return getObjectMetadata(new GetObjectMetadataRequest(bucketName, key)); }
/** * Sets the optional customer-provided server-side encryption key to use * when retrieving the metadata of a server-side encrypted object, and * retuns the updated request object so that additional method calls can be * chained together. * * @param sseKey * The optional customer-provided server-side encryption key to * use when retrieving the metadata of a server-side encrypted * object. * * @return This updated request object so that additional method calls can * be chained together. */ public GetObjectMetadataRequest withSSECustomerKey(SSECustomerKey sseKey) { setSSECustomerKey(sseKey); return this; }
@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) throws SdkClientException, AmazonServiceException { getObjectMetadataRequest = beforeClientExecution(getObjectMetadataRequest); rejectNull(getObjectMetadataRequest, "The GetObjectMetadataRequest parameter must be specified when requesting an object's metadata"); String bucketName = getObjectMetadataRequest.getBucketName(); String key = getObjectMetadataRequest.getKey(); String versionId = getObjectMetadataRequest.getVersionId(); rejectNull(bucketName, "The bucket name parameter must be specified when requesting an object's metadata"); rejectNull(key, "The key parameter must be specified when requesting an object's metadata"); Request<GetObjectMetadataRequest> request = createRequest(bucketName, key, getObjectMetadataRequest, HttpMethodName.HEAD); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "HeadObject"); if (versionId != null) request.addParameter("versionId", versionId); populateRequesterPaysHeader(request, getObjectMetadataRequest.isRequesterPays()); addPartNumberIfNotNull(request, getObjectMetadataRequest.getPartNumber()); populateSSE_C(request, getObjectMetadataRequest.getSSECustomerKey()); return invoke(request, new S3MetadataResponseHandler(), bucketName, key); }
/** * Creates a #GetObjectMetadataRequest by copying values for common members * from the input #GetObjectRequest. */ public static GetObjectMetadataRequest createGetObjectMetadataRequestFrom(GetObjectRequest getObjectRequest) { return new GetObjectMetadataRequest(getObjectRequest.getBucketName(), getObjectRequest.getKey()) .withVersionId(getObjectRequest.getVersionId()) .withRequesterPays(getObjectRequest.isRequesterPays()) .withSSECustomerKey(getObjectRequest.getSSECustomerKey()) .withPartNumber(getObjectRequest.getPartNumber()); } }
listenerChain); getObjectRequest.setGeneralProgressListener(listeners); final GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest( getObjectRequest.getBucketName(), getObjectRequest.getKey()); getObjectMetadataRequest.setSSECustomerKey(getObjectRequest.getSSECustomerKey());
GetObjectMetadataRequest req = new GetObjectMetadataRequest(bucket.get(), key.get()); req.setVersionId(versionId.get()); sseKey.setMd5(md5.get()); req.setSSECustomerKey(sseKey);
private ObjectMetadata getObjectMetadata() { if (this.objectMetadata == null) { try { GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(this.bucketName, this.objectName); if (this.versionId != null) { metadataRequest.setVersionId(this.versionId); } this.objectMetadata = this.amazonS3.getObjectMetadata(metadataRequest); } catch (AmazonS3Exception e) { // Catch 404 (object not found) and 301 (bucket not found, moved permanently) if (e.getStatusCode() == 404 || e.getStatusCode() == 301) { this.objectMetadata = null; } else { throw e; } } } return this.objectMetadata; }
new GetObjectMetadataRequest( copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()) .withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey());
/** * Sets the optional version ID of the object version whose metadata is * being retrieved. * Returns this {@link GetObjectMetadataRequest}, enabling additional method * calls to be chained together. * If not specified, the latest version will be used. * * @param versionId * The optional version ID of the object version whose metadata * is being retrieved. * * @return This {@link GetObjectMetadataRequest}, enabling additional method * calls to be chained together. * * @see GetObjectMetadataRequest#getVersionId() * @see GetObjectMetadataRequest#setVersionId(String) */ public GetObjectMetadataRequest withVersionId(String versionId) { setVersionId(versionId); return this; }
@Test public void testUnderscoreBucket() throws Exception { Configuration config = new Configuration(); config.setBoolean(S3_PATH_STYLE_ACCESS, true); try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { MockAmazonS3 s3 = new MockAmazonS3(); String expectedBucketName = "test-bucket_underscore"; fs.initialize(new URI("s3n://" + expectedBucketName + "/"), config); fs.setS3Client(s3); fs.getS3ObjectMetadata(new Path("/test/path")); assertEquals(expectedBucketName, s3.getGetObjectMetadataRequest().getBucketName()); } }
@Override public CopyObjectRequest decorate(CopyObjectRequest request) { // Note: users might want to use a different key when they copy existing objects. This might additionally need to // manage key history or support updating keys at run time, either of which requires a huge refactoring. We simply // don't support changing keys for now. return request.withSourceSSECustomerKey(key) .withDestinationSSECustomerKey(key); } }
@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) { if (getObjectMetadataRequest.getKey().equals("empty-dir/")) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(S3_DIRECTORY_OBJECT_CONTENT_TYPE); return objectMetadata; } return super.getObjectMetadata(getObjectMetadataRequest); } };
copyObjectRequest.getDestinationKey(); GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest( copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()) .withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey()) .withRequesterPays(copyObjectRequest.isRequesterPays()) .withVersionId(copyObjectRequest.getSourceVersionId());
private ObjectMetadata getObjectMetadata(S3ResourceId s3ResourceId) throws AmazonClientException { GetObjectMetadataRequest request = new GetObjectMetadataRequest(s3ResourceId.getBucket(), s3ResourceId.getKey()); request.setSSECustomerKey(options.getSSECustomerKey()); return amazonS3.getObjectMetadata(request); }
private ObjectMetadata getObjectMetadata() { if (this.objectMetadata == null) { try { GetObjectMetadataRequest metadataRequest = new GetObjectMetadataRequest(this.bucketName, this.objectName); if (this.versionId != null) { metadataRequest.setVersionId(this.versionId); } this.objectMetadata = this.amazonS3.getObjectMetadata(metadataRequest); } catch (AmazonS3Exception e) { // Catch 404 (object not found) and 301 (bucket not found, moved permanently) if (e.getStatusCode() == 404 || e.getStatusCode() == 301) { this.objectMetadata = null; } else { throw e; } } } return this.objectMetadata; }
new GetObjectMetadataRequest( copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()) .withSSECustomerKey(copyObjectRequest.getSourceSSECustomerKey());
/** * Constructs a new * {@link GetObjectMetadataRequest} * with basic options. * * @param bucketName * The name of the bucket containing the object whose metadata * is being retrieved. * @param key * The key of the object whose metadata is being retrieved. * @param versionId * The version ID of the object version whose metadata is being * retrieved. * * @see GetObjectMetadataRequest#GetObjectMetadataRequest(String bucketName, String key) */ public GetObjectMetadataRequest(String bucketName, String key, String versionId) { this(bucketName, key); setVersionId(versionId); }
@Test public void testUnderscoreBucket() throws Exception { Configuration config = new Configuration(); config.setBoolean(S3_PATH_STYLE_ACCESS, true); try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { MockAmazonS3 s3 = new MockAmazonS3(); String expectedBucketName = "test-bucket_underscore"; fs.initialize(new URI("s3n://" + expectedBucketName + "/"), config); fs.setS3Client(s3); fs.getS3ObjectMetadata(new Path("/test/path")); assertEquals(expectedBucketName, s3.getGetObjectMetadataRequest().getBucketName()); } }
@Override public CopyObjectRequest decorate(CopyObjectRequest request) { // Note: users might want to use a different key when they copy existing objects. This might additionally need to // manage key history or support updating keys at run time, either of which requires a huge refactoring. We simply // don't support changing keys for now. return request.withSourceSSECustomerKey(key) .withDestinationSSECustomerKey(key); } }
@Override public ObjectMetadata getObjectMetadata(String bucketName, String key) throws SdkClientException, AmazonServiceException { return getObjectMetadata(new GetObjectMetadataRequest(bucketName, key)); }