use of com.qcloud.cos.model.ListMultipartUploadsRequest in project cos-java-sdk-v5 by tencentyun.
the class MultipartUploadTest method testListMultipartUploads.
@Test
public void testListMultipartUploads() {
if (!judgeUserInfoValid()) {
return;
}
String key = "ut/testListMultipart.txt";
String uploadId = testInitMultipart(key);
ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(bucket);
listMultipartUploadsRequest.setMaxUploads(100);
listMultipartUploadsRequest.setPrefix("ut/");
while (true) {
MultipartUploadListing multipartUploadListing = cosclient.listMultipartUploads(listMultipartUploadsRequest);
List<MultipartUpload> multipartUploads = multipartUploadListing.getMultipartUploads();
for (MultipartUpload mUpload : multipartUploads) {
if (mUpload.getUploadId().equals(uploadId)) {
assertEquals(key, mUpload.getKey());
return;
}
}
if (!multipartUploadListing.isTruncated()) {
break;
}
listMultipartUploadsRequest.setKeyMarker(multipartUploadListing.getNextKeyMarker());
listMultipartUploadsRequest.setUploadIdMarker(multipartUploadListing.getNextUploadIdMarker());
}
}
use of com.qcloud.cos.model.ListMultipartUploadsRequest in project cos-java-sdk-v5 by tencentyun.
the class TransferManager method abortMultipartUploads.
/**
* <p>
* Aborts any multipart uploads that were initiated before the specified date.
* </p>
* <p>
* This method is useful for cleaning up any interrupted multipart uploads.
* <code>TransferManager</code> attempts to abort any failed uploads, but in some cases this may
* not be possible, such as if network connectivity is completely lost.
* </p>
*
* @param bucketName The name of the bucket containing the multipart uploads to abort.
* @param date The date indicating which multipart uploads should be aborted.
*/
public void abortMultipartUploads(String bucketName, Date date) throws CosServiceException, CosClientException {
MultipartUploadListing uploadListing = cos.listMultipartUploads(appendSingleObjectUserAgent(new ListMultipartUploadsRequest(bucketName)));
do {
for (MultipartUpload upload : uploadListing.getMultipartUploads()) {
if (upload.getInitiated().compareTo(date) < 0) {
cos.abortMultipartUpload(appendSingleObjectUserAgent(new AbortMultipartUploadRequest(bucketName, upload.getKey(), upload.getUploadId())));
}
}
ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(bucketName).withUploadIdMarker(uploadListing.getNextUploadIdMarker()).withKeyMarker(uploadListing.getNextKeyMarker());
uploadListing = cos.listMultipartUploads(appendSingleObjectUserAgent(request));
} while (uploadListing.isTruncated());
}
use of com.qcloud.cos.model.ListMultipartUploadsRequest in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method abortAllNotFinishedMultipartUpload.
private static void abortAllNotFinishedMultipartUpload() throws Exception {
ListMultipartUploadsRequest listMultipartUploadsRequest = new ListMultipartUploadsRequest(bucket);
MultipartUploadListing multipartUploadListing = null;
while (true) {
multipartUploadListing = cosclient.listMultipartUploads(listMultipartUploadsRequest);
List<MultipartUpload> multipartUploads = multipartUploadListing.getMultipartUploads();
for (MultipartUpload mUpload : multipartUploads) {
String key = mUpload.getKey();
String uploadId = mUpload.getUploadId();
cosclient.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId));
}
if (!multipartUploadListing.isTruncated()) {
break;
}
listMultipartUploadsRequest.setKeyMarker(multipartUploadListing.getNextKeyMarker());
listMultipartUploadsRequest.setUploadIdMarker(multipartUploadListing.getNextUploadIdMarker());
}
}
Aggregations