use of com.qcloud.cos.model.PartSummary in project cos-java-sdk-v5 by tencentyun.
the class UploadCallable method uploadPartsInParallel.
/**
* Submits a callable for each part to upload to our thread pool and records its corresponding
* Future.
*/
private void uploadPartsInParallel(UploadPartRequestFactory requestFactory, String uploadId) {
Map<Integer, PartSummary> partNumbers = identifyExistingPartsForResume(uploadId);
while (requestFactory.hasMoreRequests()) {
if (threadPool.isShutdown())
throw new CancellationException("TransferManager has been shutdown");
UploadPartRequest request = requestFactory.getNextUploadPartRequest();
if (partNumbers.containsKey(request.getPartNumber())) {
PartSummary summary = partNumbers.get(request.getPartNumber());
eTagsToSkip.add(new PartETag(request.getPartNumber(), summary.getETag()));
transferProgress.updateProgress(summary.getSize());
continue;
}
futures.add(threadPool.submit(new UploadPartCallable(cos, request)));
}
}
use of com.qcloud.cos.model.PartSummary in project cos-java-sdk-v5 by tencentyun.
the class MultipartUploadDemo method listPartDemo.
// list part用于获取已上传的分片, 如果已上传的分片数量较多, 需要循环多次调用list part获取已上传的所有的分片
public static List<PartETag> listPartDemo(String uploadId) {
// 1 初始化用户身份信息(secretId, secretKey)
COSCredentials cred = new BasicCOSCredentials("AKIDXXXXXXXX", "1A2Z3YYYYYYYYYY");
// 2 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
// bucket名需包含appid
String bucketName = "mybucket-1251668577";
String key = "aaa/bbb.txt";
// uploadid(通过initiateMultipartUpload或者ListMultipartUploads获取)
// 用于保存已上传的分片信息
List<PartETag> partETags = new LinkedList<>();
PartListing partListing = null;
ListPartsRequest listPartsRequest = new ListPartsRequest(bucketName, key, uploadId);
do {
try {
partListing = cosclient.listParts(listPartsRequest);
} catch (CosServiceException e) {
throw e;
} catch (CosClientException e) {
throw e;
}
for (PartSummary partSummary : partListing.getParts()) {
partETags.add(new PartETag(partSummary.getPartNumber(), partSummary.getETag()));
}
listPartsRequest.setPartNumberMarker(partListing.getNextPartNumberMarker());
} while (partListing.isTruncated());
cosclient.shutdown();
return partETags;
}
use of com.qcloud.cos.model.PartSummary in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method testListMultipart.
protected List<PartETag> testListMultipart(String key, String uploadId, int expectedPartNum, List<String> originDataMd5Array) {
List<PartETag> partETags = new LinkedList<>();
PartListing partListing = null;
ListPartsRequest listPartsRequest = new ListPartsRequest(bucket, key, uploadId);
int currentPartNum = 0;
do {
partListing = cosclient.listParts(listPartsRequest);
for (PartSummary partSummary : partListing.getParts()) {
++currentPartNum;
assertEquals(currentPartNum, partSummary.getPartNumber());
if (useClientEncryption) {
assertEquals(false, partSummary.getETag().equals(originDataMd5Array.get(currentPartNum - 1)));
} else {
assertEquals(true, partSummary.getETag().equals(originDataMd5Array.get(currentPartNum - 1)));
}
partETags.add(new PartETag(partSummary.getPartNumber(), partSummary.getETag()));
}
listPartsRequest.setPartNumberMarker(partListing.getNextPartNumberMarker());
} while (partListing.isTruncated());
assertEquals(expectedPartNum, currentPartNum);
return partETags;
}
use of com.qcloud.cos.model.PartSummary in project cos-java-sdk-v5 by tencentyun.
the class UploadCallable method identifyExistingPartsForResume.
private Map<Integer, PartSummary> identifyExistingPartsForResume(String uploadId) {
Map<Integer, PartSummary> partNumbers = new HashMap<Integer, PartSummary>();
if (uploadId == null) {
return partNumbers;
}
int partNumber = 0;
while (true) {
ListPartsRequest listPartsRequest = new ListPartsRequest(origReq.getBucketName(), origReq.getKey(), uploadId).withPartNumberMarker(partNumber);
TransferManagerUtils.populateEndpointAddr(origReq, listPartsRequest);
PartListing parts = cos.listParts(listPartsRequest);
for (PartSummary partSummary : parts.getParts()) {
partNumbers.put(partSummary.getPartNumber(), partSummary);
}
if (!parts.isTruncated()) {
return partNumbers;
}
partNumber = parts.getNextPartNumberMarker();
}
}
Aggregations