Search in sources :

Example 1 with CopyImpl

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

the class TransferManager method copy.

/**
 * <p>
 * Schedules a new transfer to copy data from one object to another . This method is
 * non-blocking and returns immediately (i.e. before the copy has finished).
 * </p>
 * <p>
 * Note: You need to use this method if the {@link TransferManager} is created with a regional
 * COS client and the source & destination buckets are in different regions.
 * </p>
 * <p>
 * <code>TransferManager</code> doesn't support copying of encrypted objects whose encryption
 * materials are stored in an instruction file.
 * </p>
 * <p>
 * Use the returned <code>Copy</code> object to check if the copy is complete.
 * </p>
 * <p>
 * If resources are available, the copy request will begin immediately. Otherwise, the copy is
 * scheduled and started as soon as resources become available.
 * </p>
 *
 * <p>
 * <b>Note:</b> If the {@link TransferManager} is created with a regional COS client and the
 * source & destination buckets are in different regions, use the
 * {@link #copy(CopyObjectRequest, COS, TransferStateChangeListener)} method.
 * </p>
 *
 * @param copyObjectRequest The request containing all the parameters for the copy.
 * @param srcCOS An COS client constructed for the region in which the source object's bucket is
 *        located.
 * @param stateChangeListener The transfer state change listener to monitor the copy request
 * @return A new <code>Copy</code> object to use to check the state of the copy request being
 *         processed.
 * @throws CosClientException If any errors are encountered in the client while making the
 *         request or handling the response.
 * @throws CosServiceException If any errors occurred in Qcloud COS while processing the
 *         request.
 */
public Copy copy(final CopyObjectRequest copyObjectRequest, final COS srcCOS, final TransferStateChangeListener stateChangeListener) throws CosServiceException, CosClientException {
    appendSingleObjectUserAgent(copyObjectRequest);
    assertParameterNotNull(copyObjectRequest.getSourceBucketName(), "The source bucket name must be specified when a copy request is initiated.");
    assertParameterNotNull(copyObjectRequest.getSourceKey(), "The source object key must be specified when a copy request is initiated.");
    assertParameterNotNull(copyObjectRequest.getDestinationBucketName(), "The destination bucket name must be specified when a copy request is initiated.");
    assertParameterNotNull(copyObjectRequest.getDestinationKey(), "The destination object key must be specified when a copy request is initiated.");
    assertParameterNotNull(srcCOS, "The srcCOS parameter is mandatory");
    String description = "Copying object from " + copyObjectRequest.getSourceBucketName() + "/" + copyObjectRequest.getSourceKey() + " to " + copyObjectRequest.getDestinationBucketName() + "/" + copyObjectRequest.getDestinationKey();
    GetObjectMetadataRequest getObjectMetadataRequest = new GetObjectMetadataRequest(copyObjectRequest.getSourceBucketName(), copyObjectRequest.getSourceKey()).withVersionId(copyObjectRequest.getSourceVersionId());
    ObjectMetadata metadata = srcCOS.getObjectMetadata(getObjectMetadataRequest);
    TransferProgress transferProgress = new TransferProgress();
    transferProgress.setTotalBytesToTransfer(metadata.getContentLength());
    ProgressListenerChain listenerChain = new ProgressListenerChain(new TransferProgressUpdatingListener(transferProgress));
    CopyImpl copy = new CopyImpl(description, transferProgress, listenerChain, stateChangeListener);
    CopyCallable copyCallable = new CopyCallable(this, threadPool, copy, copyObjectRequest, metadata, listenerChain);
    CopyMonitor watcher = CopyMonitor.create(this, copy, threadPool, copyCallable, copyObjectRequest, listenerChain);
    copy.setMonitor(watcher);
    return copy;
}
Also used : GetObjectMetadataRequest(com.qcloud.cos.model.GetObjectMetadataRequest) CopyImpl(com.qcloud.cos.internal.CopyImpl) COSProgressListenerChain(com.qcloud.cos.event.COSProgressListenerChain) ProgressListenerChain(com.qcloud.cos.event.ProgressListenerChain) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) TransferProgressUpdatingListener(com.qcloud.cos.event.TransferProgressUpdatingListener) MultipleFileTransferProgressUpdatingListener(com.qcloud.cos.event.MultipleFileTransferProgressUpdatingListener)

Aggregations

COSProgressListenerChain (com.qcloud.cos.event.COSProgressListenerChain)1 MultipleFileTransferProgressUpdatingListener (com.qcloud.cos.event.MultipleFileTransferProgressUpdatingListener)1 ProgressListenerChain (com.qcloud.cos.event.ProgressListenerChain)1 TransferProgressUpdatingListener (com.qcloud.cos.event.TransferProgressUpdatingListener)1 CopyImpl (com.qcloud.cos.internal.CopyImpl)1 GetObjectMetadataRequest (com.qcloud.cos.model.GetObjectMetadataRequest)1 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)1