use of software.amazon.awssdk.services.s3.model.ObjectVersion in project aws-sdk-java-v2 by aws.
the class S3IntegrationTestBase method deleteBucketAndAllContents.
protected static void deleteBucketAndAllContents(String bucketName) {
System.out.println("Deleting S3 bucket: " + bucketName);
ListObjectsResponse response = s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build());
while (true) {
if (response.contents() == null) {
break;
}
for (S3Object objectSummary : response.contents()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(objectSummary.key()).build());
}
if (response.isTruncated()) {
response = s3.listObjects(ListObjectsRequest.builder().marker(response.nextMarker()).build());
} else {
break;
}
}
ListObjectVersionsResponse versionsResponse = s3.listObjectVersions(ListObjectVersionsRequest.builder().bucket(bucketName).build());
if (versionsResponse.versions() != null) {
for (ObjectVersion s : versionsResponse.versions()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(s.key()).versionId(s.versionId()).build());
}
}
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
}
use of software.amazon.awssdk.services.s3.model.ObjectVersion in project aws-sdk-java-v2 by aws.
the class CloudTrailIntegrationTest method deleteBucketAndAllContents.
public static void deleteBucketAndAllContents(String bucketName) {
System.out.println("Deleting S3 bucket: " + bucketName);
ListObjectsResponse response = s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build());
while (true) {
if (response.contents() == null) {
break;
}
for (Iterator<?> iterator = response.contents().iterator(); iterator.hasNext(); ) {
S3Object objectSummary = (S3Object) iterator.next();
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(objectSummary.key()).build());
}
if (response.isTruncated()) {
response = s3.listObjects(ListObjectsRequest.builder().marker(response.nextMarker()).build());
} else {
break;
}
}
ListObjectVersionsResponse versionsResponse = s3.listObjectVersions(ListObjectVersionsRequest.builder().bucket(bucketName).build());
if (versionsResponse.versions() != null) {
for (ObjectVersion s : versionsResponse.versions()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(s.key()).versionId(s.versionId()).build());
}
}
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
}
Aggregations