@Test public void deleteShouldRemoveItemsFromBucket() { // given PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket("someBucket") .key("someObject") .build(); RequestBody requestBody = RequestBody.fromString("content"); testee.putObject(putObjectRequest, requestBody); testee.deleteObjects(DeleteObjectsRequest.builder().bucket("someBucket").delete(Delete.builder().objects (ObjectIdentifier.builder().key("someObject").build()).build()).build()); // when ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder() .bucket("someBucket") .build(); ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request); //then assertThat(listObjectsV2Response.contents().size(), is(0)); }
return listObjectsV2Paginator(ListObjectsV2Request.builder().applyMutation(listObjectsV2Request).build());
return listObjectsV2Paginator(ListObjectsV2Request.builder().applyMutation(listObjectsV2Request).build());
/** * <p> * Returns some or all (up to 1000) of the objects in a bucket. You can use the request parameters as selection * criteria to return a subset of the objects in a bucket. Note: ListObjectsV2 is the revised List Objects API and * we recommend you use this revised API for new application development. * </p> * <br/> * <p> * This is a convenience which creates an instance of the {@link ListObjectsV2Request.Builder} avoiding the need to * create one manually via {@link ListObjectsV2Request#builder()} * </p> * * @param listObjectsV2Request * A {@link Consumer} that will call methods on {@link ListObjectsV2Request.Builder} to create a request. * @return Result of the ListObjectsV2 operation returned by the service. * @throws NoSuchBucketException * The specified bucket does not exist. * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws S3Exception * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample S3Client.ListObjectsV2 */ default ListObjectsV2Response listObjectsV2(Consumer<ListObjectsV2Request.Builder> listObjectsV2Request) throws NoSuchBucketException, AwsServiceException, SdkClientException, S3Exception { return listObjectsV2(ListObjectsV2Request.builder().applyMutation(listObjectsV2Request).build()); }
return listObjectsV2(ListObjectsV2Request.builder().applyMutation(listObjectsV2Request).build());
@Test public void shouldListObjectsInBucket() { // given PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket("someBucket") .key("someObject") .build(); RequestBody requestBody = RequestBody.fromString("content"); testee.putObject(putObjectRequest, requestBody); // when ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder() .bucket("someBucket") .build(); ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request); //then assertThat(listObjectsV2Response.contents().size(), is(1)); assertThat(listObjectsV2Response.contents().get(0).key(), is("someObject")); }
/** * <p> * A helper method to resume the pages in case of unexpected failures. The method takes the last successful response * page as input and returns an instance of {@link ListObjectsV2Publisher} that can be used to retrieve the * consecutive pages that follows the input page. * </p> */ private final ListObjectsV2Publisher resume(ListObjectsV2Response lastSuccessfulPage) { if (nextPageFetcher.hasNextPage(lastSuccessfulPage)) { return new ListObjectsV2Publisher(client, firstRequest.toBuilder() .continuationToken(lastSuccessfulPage.nextContinuationToken()).build()); } return new ListObjectsV2Publisher(client, firstRequest, true) { @Override public void subscribe(Subscriber<? super ListObjectsV2Response> subscriber) { subscriber.onSubscribe(new EmptySubscription(subscriber)); } }; }
/** * <p> * A helper method to resume the pages in case of unexpected failures. The method takes the last successful response * page as input and returns an instance of {@link ListObjectsV2Iterable} that can be used to retrieve the * consecutive pages that follows the input page. * </p> */ private final ListObjectsV2Iterable resume(ListObjectsV2Response lastSuccessfulPage) { if (nextPageFetcher.hasNextPage(lastSuccessfulPage)) { return new ListObjectsV2Iterable(client, firstRequest.toBuilder() .continuationToken(lastSuccessfulPage.nextContinuationToken()).build()); } return new ListObjectsV2Iterable(client, firstRequest) { @Override public Iterator<ListObjectsV2Response> iterator() { return Collections.emptyIterator(); } }; }
public void deleteAllObjectsWithPrefixInBucket(final String bucketName, final String prefix) { final ListObjectsV2Response listObjectResponse = s3Client.listObjectsV2(ListObjectsV2Request.builder().bucket(bucketName).build()); if (listObjectResponse.keyCount() > 0) { DeleteObjectsRequest deleteObjectsRequest = DeleteObjectsRequest.builder() .bucket(bucketName) .delete(builder() .objects(convertS3ObjectsToObjectIdentifiers(listObjectResponse, prefix)) .build()) .build(); final DeleteObjectsResponse deleteObjectsResponse = s3Client.deleteObjects(deleteObjectsRequest); LOG.debug("deleteAllObjectsWithPrefixInBucket in bucket {} with prefix {}: {}", bucketName, prefix, deleteObjectsResponse); } else { LOG.debug("deleteAllObjectsWithPrefixInBucket listObjects found no keys in bucket {} with prefix {}: {}", bucketName, prefix, listObjectResponse); } }
public List<S3Object> listAll(final String bucketName) { final ListObjectsV2Response listObjectsV2Response = s3Client.listObjectsV2(ListObjectsV2Request.builder().bucket(bucketName).build()); if (listObjectsV2Response.keyCount() > 0) { return listObjectsV2Response.contents(); } else { return Collections.emptyList(); } }
@Override public ListObjectsV2Response nextPage(ListObjectsV2Response previousPage) { if (previousPage == null) { return client.listObjectsV2(firstRequest); } return client.listObjectsV2(firstRequest.toBuilder().continuationToken(previousPage.nextContinuationToken()).build()); } }
@Override public CompletableFuture<ListObjectsV2Response> nextPage(final ListObjectsV2Response previousPage) { if (previousPage == null) { return client.listObjectsV2(firstRequest); } return client.listObjectsV2(firstRequest.toBuilder().continuationToken(previousPage.nextContinuationToken()).build()); } }