software.amazon.awssdk.services.s3.model.HeadObjectResponse Java Examples
The following examples show how to use
software.amazon.awssdk.services.s3.model.HeadObjectResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserMetadataIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void putObject_PutsUserMetadata() throws Exception { Map<String, String> userMetadata = new HashMap<>(); userMetadata.put("thing1", "IAmThing1"); userMetadata.put("thing2", "IAmThing2"); String mixedCasePrefix = "x-AmZ-mEtA-"; String metadataKey = "test"; final String key = "user-metadata-key"; s3.putObject(PutObjectRequest.builder() .bucket(BUCKET_NAME) .key(key) .metadata(userMetadata) .overrideConfiguration(b -> b.putHeader(mixedCasePrefix + metadataKey, "test")) .build(), RequestBody.fromFile(file)); HeadObjectResponse response = s3.headObject(HeadObjectRequest.builder() .bucket(BUCKET_NAME) .key(key) .build()); Map<String, String> returnedMetadata = response.metadata(); assertThat(returnedMetadata).containsAllEntriesOf(userMetadata); assertThat(returnedMetadata).containsKey(metadataKey); }
Example #2
Source File: PutObjectHeaderTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void headObject_userMetadataReturnMixedCaseMetadata() { String lowerCaseMetadataPrefix = "x-amz-meta-"; String mixedCaseMetadataPrefix = "X-AmZ-MEta-"; String metadataKey = "foo"; String mixedCaseMetadataKey = "bAr"; stubFor(any(urlMatching(".*")) .willReturn(response().withHeader(lowerCaseMetadataPrefix + metadataKey, "test") .withHeader(mixedCaseMetadataPrefix + mixedCaseMetadataKey, "test"))); HeadObjectResponse headObjectResponse = s3Client.headObject(b -> b.key("key").bucket("bucket")); assertThat(headObjectResponse.metadata()).containsKey(metadataKey); assertThat(headObjectResponse.metadata()).containsKey(mixedCaseMetadataKey); }
Example #3
Source File: DecodeUrlEncodedResponseInterceptorTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void otherResponses_shouldNotModifyResponse() { HeadObjectResponse original = HeadObjectResponse.builder().build(); Context.ModifyResponse ctx = newContext(original); SdkResponse sdkResponse = INTERCEPTOR.modifyResponse(ctx, new ExecutionAttributes()); assertThat(original.hashCode()).isEqualTo(sdkResponse.hashCode()); }
Example #4
Source File: S3PinotFS.java From incubator-pinot with Apache License 2.0 | 5 votes |
private HeadObjectResponse getS3ObjectMetadata(URI uri) throws IOException { URI base = getBase(uri); String path = sanitizePath(base.relativize(uri).getPath()); HeadObjectRequest headObjectRequest = HeadObjectRequest.builder().bucket(uri.getHost()).key(path).build(); return _s3Client.headObject(headObjectRequest); }
Example #5
Source File: S3PinotFS.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Override public long length(URI fileUri) throws IOException { try { Preconditions.checkState(!isPathTerminatedByDelimiter(fileUri), "URI is a directory"); HeadObjectResponse s3ObjectMetadata = getS3ObjectMetadata(fileUri); Preconditions.checkState((s3ObjectMetadata != null), "File '%s' does not exist", fileUri); if (s3ObjectMetadata.contentLength() == null) { return 0; } return s3ObjectMetadata.contentLength(); } catch (Throwable t) { throw new IOException(t); } }
Example #6
Source File: S3PinotFSTest.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Test public void testMkdir() throws Exception { String folderName = "my-test-folder"; _s3PinotFS.mkdir(URI.create(String.format(FILE_FORMAT, SCHEME, BUCKET, folderName))); HeadObjectResponse headObjectResponse = _s3Client.headObject(S3TestUtils.getHeadObjectRequest(BUCKET, folderName)); Assert.assertTrue(headObjectResponse.sdkHttpResponse().isSuccessful()); }
Example #7
Source File: S3PinotFSTest.java From incubator-pinot with Apache License 2.0 | 4 votes |
@Test public void testCopyFromAndToLocal() throws Exception { String fileName = "copyFile.txt"; File fileToCopy = new File(getClass().getClassLoader().getResource(fileName).getFile()); _s3PinotFS.copyFromLocalFile(fileToCopy, URI.create(String.format(FILE_FORMAT, SCHEME, BUCKET, fileName))); HeadObjectResponse headObjectResponse = _s3Client.headObject(S3TestUtils.getHeadObjectRequest(BUCKET, fileName)); Assert.assertEquals(headObjectResponse.contentLength(), (Long) fileToCopy.length()); File fileToDownload = new File("copyFile_download.txt"); _s3PinotFS.copyToLocalFile(URI.create(String.format(FILE_FORMAT, SCHEME, BUCKET, fileName)), fileToDownload); Assert.assertEquals(fileToCopy.length(), fileToDownload.length()); fileToDownload.deleteOnExit(); }