Search in sources :

Example 1 with UploadPartRequestFactory

use of com.qcloud.cos.internal.UploadPartRequestFactory in project cos-java-sdk-v5 by tencentyun.

the class UploadCallable method uploadInParts.

/**
 * Uploads the request in multiple chunks, submitting each upload chunk task to the thread pool
 * and recording its corresponding Future object, as well as the multipart upload id.
 */
private UploadResult uploadInParts() throws Exception {
    boolean isUsingEncryption = cos instanceof COSEncryptionClient;
    long optimalPartSize = getOptimalPartSize(isUsingEncryption);
    try {
        if (multipartUploadId == null) {
            multipartUploadId = initiateMultipartUpload(origReq, isUsingEncryption, optimalPartSize);
        }
        UploadPartRequestFactory requestFactory = new UploadPartRequestFactory(origReq, multipartUploadId, optimalPartSize);
        if (TransferManagerUtils.isUploadParallelizable(origReq, isUsingEncryption)) {
            captureUploadStateIfPossible();
            uploadPartsInParallel(requestFactory, multipartUploadId);
            return null;
        } else {
            return uploadPartsInSeries(requestFactory);
        }
    } catch (Exception e) {
        publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
        performAbortMultipartUpload();
        throw e;
    } finally {
        if (origReq.getInputStream() != null) {
            try {
                origReq.getInputStream().close();
            } catch (Exception e) {
                log.warn("Unable to cleanly close input stream: " + e.getMessage(), e);
            }
        }
    }
}
Also used : UploadPartRequestFactory(com.qcloud.cos.internal.UploadPartRequestFactory) COSEncryptionClient(com.qcloud.cos.COSEncryptionClient) CancellationException(java.util.concurrent.CancellationException)

Aggregations

COSEncryptionClient (com.qcloud.cos.COSEncryptionClient)1 UploadPartRequestFactory (com.qcloud.cos.internal.UploadPartRequestFactory)1 CancellationException (java.util.concurrent.CancellationException)1