当前位置: 首页>>代码示例>>Java>>正文


Java ListObjectsV2Response类代码示例

本文整理汇总了Java中software.amazon.awssdk.services.s3.model.ListObjectsV2Response的典型用法代码示例。如果您正苦于以下问题:Java ListObjectsV2Response类的具体用法?Java ListObjectsV2Response怎么用?Java ListObjectsV2Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ListObjectsV2Response类属于software.amazon.awssdk.services.s3.model包,在下文中一共展示了ListObjectsV2Response类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testListNoParameters

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListNoParameters() {
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder().bucket(bucketName).build());
    List<S3Object> objects = result.contents();

    assertEquals(keys.size(), objects.size());
    assertThat(keys.size(), equalTo(result.keyCount()));
    assertEquals(bucketName, result.name());
    assertS3ObjectSummariesAreValid(objects, false);
    assertNotNull(result.maxKeys());

    // We didn't use a delimiter, so we expect these to be empty/null
    assertNull(result.delimiter());

    // We don't expect any truncated results
    assertFalse(result.isTruncated());
    assertNull(result.nextContinuationToken());

    // We didn't set other request parameters, so we expect them to be empty
    assertNull(result.encodingType());
    assertThat(result.prefix(), equalTo(""));
    assertNull(result.continuationToken());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:24,代码来源:S3ListObjectsV2IntegrationTest.java

示例2: testListWithEncodingType

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
@Ignore
@ReviewBeforeRelease("Automatic decoding is not hooked up yet.")
public void testListWithEncodingType() {
    String encodingType = "url";
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .prefix(KEY_NAME_WITH_SPECIAL_CHARS)
                                                                        .encodingType(encodingType)
                                                                        .build());
    List<S3Object> objects = result.contents();

    // EncodingType should be returned in the response.
    assertEquals(encodingType, result.encodingTypeString());

    System.out.println(result.contents().get(0).key());

    // The key name returned in the response should have been decoded
    // from the URL encoded form S3 returned us.
    assertEquals(KEY_NAME_WITH_SPECIAL_CHARS,
                 objects.get(0).key());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:23,代码来源:S3ListObjectsV2IntegrationTest.java

示例3: testListWithPrefixAndStartAfter

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListWithPrefixAndStartAfter() {
    String prefix = "key";
    String startAfter = "key-01";
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .prefix(prefix)
                                                                        .startAfter(startAfter)
                                                                        .build());
    List<S3Object> objects = result.contents();

    assertEquals(BUCKET_OBJECTS - 1, objects.size());
    assertEquals(bucketName, result.name());
    assertS3ObjectSummariesAreValid(objects, false);
    assertEquals(startAfter, result.startAfter());
    assertEquals(prefix, result.prefix());

    // We didn't use a delimiter, so we expect it to be empty/null
    assertNull(result.delimiter());

    // We don't expect any truncated results
    assertFalse(result.isTruncated());
    assertNull(result.nextContinuationToken());

    // We didn't set any other request parameters, so we expect them to be
    // set to the defaults.
    assertTrue(result.maxKeys() >= 1000);
    assertNull(result.encodingType());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:30,代码来源:S3ListObjectsV2IntegrationTest.java

示例4: testListWithPrefixAndDelimiter

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListWithPrefixAndDelimiter() {
    String prefix = "a";
    String delimiter = "/";
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .prefix(prefix)
                                                                        .delimiter(delimiter)
                                                                        .build());

    List<S3Object> objects = result.contents();

    assertEquals(1, objects.size());
    assertEquals(bucketName, result.name());
    assertS3ObjectSummariesAreValid(objects, false);
    assertEquals(prefix, result.prefix());
    assertEquals(delimiter, result.delimiter());

    // We don't expect any truncated results
    assertFalse(result.isTruncated());
    assertNull(result.nextContinuationToken());

    // We didn't set other request parameters, so we expect them to be empty
    assertNull(result.startAfter());
    assertNull(result.encodingType());
    assertTrue(result.maxKeys() >= 1000);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:28,代码来源:S3ListObjectsV2IntegrationTest.java

示例5: testListWithMaxKeys

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListWithMaxKeys() {
    int maxKeys = 4;
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .maxKeys(maxKeys)
                                                                        .build());

    List<S3Object> objects = result.contents();

    assertEquals(maxKeys, objects.size());
    assertEquals(bucketName, result.name());
    assertThat(maxKeys, equalTo(result.maxKeys()));
    assertS3ObjectSummariesAreValid(objects, false);

    // We didn't use a delimiter, so we expect this to be empty/null
    assertNull(result.delimiter());

    // We expect truncated results since we set maxKeys
    assertTrue(result.isTruncated());
    assertNotNull(result.nextContinuationToken());
    assertTrue(result.nextContinuationToken().length() > 1);

    // URL encoding is requested by default

    // We didn't set other request parameters, so we expect them to be empty
    assertNull(result.encodingType());
    assertThat(result.prefix(), isEmptyString());
    assertNull(result.startAfter());
    assertNull(result.delimiter());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:32,代码来源:S3ListObjectsV2IntegrationTest.java

示例6: testListWithFetchOwner

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListWithFetchOwner() {
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .fetchOwner(true)
                                                                        .build());
    List<S3Object> objects = result.contents();
    assertS3ObjectSummariesAreValid(objects, true);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:10,代码来源:S3ListObjectsV2IntegrationTest.java

示例7: testListPagination

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
@Test
public void testListPagination() {
    int firstRequestMaxKeys = 4;
    String prefix = "key";
    ListObjectsV2Response result = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                        .bucket(bucketName)
                                                                        .prefix(prefix)
                                                                        .maxKeys(firstRequestMaxKeys)
                                                                        .build());
    List<S3Object> objects = result.contents();

    assertEquals(firstRequestMaxKeys, objects.size());
    assertEquals(bucketName, result.name());
    assertEquals(prefix, result.prefix());
    assertNotNull(result.nextContinuationToken());
    assertTrue(result.isTruncated());
    assertS3ObjectSummariesAreValid(objects, false);

    for (int i = 0; i < firstRequestMaxKeys; i++) {
        assertEquals(keys.get(i), objects.get(i).key());
    }

    ListObjectsV2Response nextResults = s3.listObjectsV2(ListObjectsV2Request.builder()
                                                                             .bucket(bucketName)
                                                                             .prefix(prefix)
                                                                             .continuationToken(
                                                                                     result.nextContinuationToken())
                                                                             .build());
    List<S3Object> nextObjects = nextResults.contents();

    assertNull(nextResults.nextContinuationToken());
    assertEquals(nextResults.continuationToken(), result.nextContinuationToken());
    assertFalse(nextResults.isTruncated());
    assertEquals(prefix, nextResults.prefix());
    assertS3ObjectSummariesAreValid(nextObjects, false);
    assertEquals(nextObjects.size(), BUCKET_OBJECTS - firstRequestMaxKeys);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:38,代码来源:S3ListObjectsV2IntegrationTest.java

示例8: main

import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Region region = Region.US_WEST_2;
    s3 = S3Client.builder().region(region).build();

    String bucket = "bucket" + System.currentTimeMillis();

    createBucket(bucket, region);
    // Delete empty bucket
    deleteEmptyBucket(bucket);

    String bucket2 = "bucket" + System.currentTimeMillis();
    createBucket(bucket2, region);
    putObjects(bucket2);

    // Delete non-empty bucket
    // To delete a bucket, all the objects in the bucket should be deleted first
    ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder().bucket(bucket2).build();
    ListObjectsV2Response listObjectsV2Response;
    do {
        listObjectsV2Response = s3.listObjectsV2(listObjectsV2Request);
        for (S3Object s3Object : listObjectsV2Response.contents()) {
            s3.deleteObject(DeleteObjectRequest.builder().bucket(bucket2).key(s3Object.key()).build());
        }

        listObjectsV2Request = ListObjectsV2Request.builder().bucket(bucket2)
                                                   .continuationToken(listObjectsV2Response.nextContinuationToken())
                                                   .build();

    } while (listObjectsV2Response.isTruncated());

    // Now the bucket is empty and we can delete it
    deleteEmptyBucket(bucket2);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:34,代码来源:S3BucketDeletion.java


注:本文中的software.amazon.awssdk.services.s3.model.ListObjectsV2Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。