Search in sources :

Example 1 with EncodingType

use of software.amazon.awssdk.services.s3.model.EncodingType in project knime-cloud by knime.

the class S3FileSystemProvider method dirIsEmpty.

@SuppressWarnings("resource")
private static boolean dirIsEmpty(final S3Path dir) throws IOException {
    final MultiRegionS3Client client = dir.getFileSystem().getClient();
    final ListObjectsV2Request listRequest = // 
    ListObjectsV2Request.builder().bucket(// 
    dir.getBucketName()).prefix(// 
    dir.getBlobName()).delimiter(// 
    dir.getFileSystem().getSeparator()).encodingType(// 
    "url").startAfter(// 
    dir.getBlobName()).maxKeys(// 
    1).build();
    try {
        return client.listObjects(listRequest).keyCount() == 0;
    } catch (SdkException e) {
        throw AwsUtils.toIOE(e, dir);
    }
}
Also used : ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) SdkException(software.amazon.awssdk.core.exception.SdkException) MultiRegionS3Client(org.knime.cloud.aws.filehandling.s3.MultiRegionS3Client)

Example 2 with EncodingType

use of software.amazon.awssdk.services.s3.model.EncodingType in project aws-sdk-java-v2 by aws.

the class DecodeUrlEncodedResponseInterceptorTest method encodingTypeNotSet_doesNotDecodeListObjectsV2ResponseParts.

@Test
public void encodingTypeNotSet_doesNotDecodeListObjectsV2ResponseParts() {
    ListObjectsV2Response original = V2_TEST_ENCODED_RESPONSE.toBuilder().encodingType((String) null).build();
    Context.ModifyResponse ctx = newContext(original);
    ListObjectsV2Response fromInterceptor = (ListObjectsV2Response) INTERCEPTOR.modifyResponse(ctx, new ExecutionAttributes());
    assertThat(fromInterceptor).isEqualTo(original);
}
Also used : Context(software.amazon.awssdk.core.interceptor.Context) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) Test(org.junit.jupiter.api.Test)

Example 3 with EncodingType

use of software.amazon.awssdk.services.s3.model.EncodingType in project aws-sdk-java-v2 by aws.

the class UrlEncodingIntegrationTest method listObjectWithUrlEncodingType_shouldDecode.

@Test
public void listObjectWithUrlEncodingType_shouldDecode() {
    ListObjectsResponse listObjectsV2Response = s3.listObjects(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL));
    listObjectsV2Response.contents().forEach(c -> assertKeyIsDecoded(c.key()));
    ListObjectVersionsResponse asyncResponse = s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join();
    asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key()));
}
Also used : AfterClass(org.junit.AfterClass) ListMultipartUploadsResponse(software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CreateMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse) S3BucketUtils.temporaryBucketName(software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName) Test(org.junit.Test) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) EncodingType(software.amazon.awssdk.services.s3.model.EncodingType) ListObjectsResponse(software.amazon.awssdk.services.s3.model.ListObjectsResponse) RequestBody(software.amazon.awssdk.core.sync.RequestBody) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) UploadPartResponse(software.amazon.awssdk.services.s3.model.UploadPartResponse) ListObjectsResponse(software.amazon.awssdk.services.s3.model.ListObjectsResponse) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) Test(org.junit.Test)

Example 4 with EncodingType

use of software.amazon.awssdk.services.s3.model.EncodingType in project aws-sdk-java-v2 by aws.

the class UrlEncodingIntegrationTest method listObjectVersionsWithUrlEncodingType_shouldDecode.

@Test
public void listObjectVersionsWithUrlEncodingType_shouldDecode() {
    ListObjectVersionsResponse listObjectVersionsResponse = s3.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL));
    listObjectVersionsResponse.versions().forEach(v -> assertKeyIsDecoded(v.key()));
    ListObjectVersionsResponse asyncResponse = s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join();
    asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key()));
}
Also used : AfterClass(org.junit.AfterClass) ListMultipartUploadsResponse(software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse) BeforeClass(org.junit.BeforeClass) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CreateMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse) S3BucketUtils.temporaryBucketName(software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName) Test(org.junit.Test) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) EncodingType(software.amazon.awssdk.services.s3.model.EncodingType) ListObjectsResponse(software.amazon.awssdk.services.s3.model.ListObjectsResponse) RequestBody(software.amazon.awssdk.core.sync.RequestBody) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) UploadPartResponse(software.amazon.awssdk.services.s3.model.UploadPartResponse) ListObjectVersionsResponse(software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse) Test(org.junit.Test)

Example 5 with EncodingType

use of software.amazon.awssdk.services.s3.model.EncodingType in project aws-sdk-java-v2 by aws.

the class ListObjectsIntegrationTest method listObjectsWithAllElements.

@Test
public void listObjectsWithAllElements() {
    String delimiter = "/";
    String marker = "aaa";
    ListObjectsResponse result = s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).prefix(KEY_NAME_WITH_SPECIAL_CHARS).marker(marker).encodingType(EncodingType.URL).delimiter(delimiter).build());
    List<S3Object> objects = result.contents();
    assertEquals(bucketName, result.name());
    assertS3ObjectSummariesAreValid(objects);
    assertEquals(marker, result.marker());
    assertEquals(delimiter, result.delimiter());
    assertEquals(KEY_NAME_WITH_SPECIAL_CHARS, result.prefix());
    assertFalse(result.isTruncated());
    assertTrue(result.maxKeys() >= 1000);
}
Also used : ListObjectsResponse(software.amazon.awssdk.services.s3.model.ListObjectsResponse) S3Object(software.amazon.awssdk.services.s3.model.S3Object) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ListObjectsResponse (software.amazon.awssdk.services.s3.model.ListObjectsResponse)5 ListObjectsV2Response (software.amazon.awssdk.services.s3.model.ListObjectsV2Response)5 EncodingType (software.amazon.awssdk.services.s3.model.EncodingType)4 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 AfterClass (org.junit.AfterClass)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.jupiter.api.Test)3 RequestBody (software.amazon.awssdk.core.sync.RequestBody)3 CreateMultipartUploadResponse (software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse)3 ListMultipartUploadsResponse (software.amazon.awssdk.services.s3.model.ListMultipartUploadsResponse)3 ListObjectVersionsResponse (software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse)3 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)3 UploadPartResponse (software.amazon.awssdk.services.s3.model.UploadPartResponse)3 S3BucketUtils.temporaryBucketName (software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName)3 Context (software.amazon.awssdk.core.interceptor.Context)2 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)2 ListObjectsV2Request (software.amazon.awssdk.services.s3.model.ListObjectsV2Request)2 S3Object (software.amazon.awssdk.services.s3.model.S3Object)2