use of com.qcloud.cos.model.GetBucketVersioningConfigurationRequest in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method clearBucket.
private static void clearBucket() throws Exception {
abortAllNotFinishedMultipartUpload();
// 先判断bucket是否开启了版本控制
GetBucketVersioningConfigurationRequest getBucketVersioningConfigurationRequest = new GetBucketVersioningConfigurationRequest(bucket);
BucketVersioningConfiguration bucketVersioningConfiguration = cosclient.getBucketVersioningConfiguration(getBucketVersioningConfigurationRequest);
if (bucketVersioningConfiguration.getStatus().compareToIgnoreCase(BucketVersioningConfiguration.ENABLED) == 0) {
clearObjectVersions();
}
String nextMarker = "";
boolean isTruncated = false;
do {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
listObjectsRequest.setBucketName(bucket);
listObjectsRequest.setMaxKeys(1000);
listObjectsRequest.setPrefix("");
listObjectsRequest.setDelimiter("");
listObjectsRequest.setMarker(nextMarker);
ObjectListing objectListing = cosclient.listObjects(listObjectsRequest);
for (COSObjectSummary cosObjectSummary : objectListing.getObjectSummaries()) {
String key = cosObjectSummary.getKey();
// 删除这个key
System.out.println(key);
cosclient.deleteObject(bucket, key);
}
nextMarker = objectListing.getNextMarker();
isTruncated = objectListing.isTruncated();
} while (isTruncated);
}
Aggregations