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;
}
Aggregations