use of com.qcloud.cos.model.CopyObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerTest method testTransferManagerCopySmallFileFromSameRegion.
// transfer manager对相同园区使用put object copy
@Ignore
public void testTransferManagerCopySmallFileFromSameRegion() throws CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
String srcRegion = region;
ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
String srcBucketName = bucket;
String srcKey = "ut_copy/len1G.txt";
String destKey = "ut_copy_dest/len1G_2.txt";
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(srcBucketName, srcKey, bucket, destKey);
Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
CopyResult copyResult = copy.waitForCopyResult();
assertNotNull(copyResult.getRequestId());
assertNotNull(copyResult.getDateStr());
}
use of com.qcloud.cos.model.CopyObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerTest method testTransferManagerCopyBigFileFromDiffRegion.
// transfer manager对不同园区5G以上文件进行分块拷贝
@Ignore
public void testTransferManagerCopyBigFileFromDiffRegion() throws CosServiceException, CosClientException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
String srcRegion = "ap-guangzhou";
ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
String srcBucketName = "chengwus3gz-1251668577";
String srcKey = "ut_copy/len10G_1.txt";
String destKey = "ut_copy_dest/len10G_1.txt";
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(new Region(srcRegion), srcBucketName, srcKey, bucket, destKey);
Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
copy.waitForCompletion();
clearObject(destKey);
}
use of com.qcloud.cos.model.CopyObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerDemo method copyFileForSameRegion.
// copy接口支持根据文件大小自动选择copy或者分块copy
// 以下代码展示同园区拷贝, 即将同园区的文件拷贝到另一个园区
public static void copyFileForSameRegion() {
// 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-beijing-1"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
ExecutorService threadPool = Executors.newFixedThreadPool(32);
// 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
TransferManager transferManager = new TransferManager(cosclient, threadPool);
TransferManagerConfiguration transferManagerConfiguration = new TransferManagerConfiguration();
transferManagerConfiguration.setMultipartCopyThreshold(20 * 1024 * 1024);
transferManager.setConfiguration(transferManagerConfiguration);
// 要拷贝的bucket region, 支持跨园区拷贝
Region srcBucketRegion = new Region("ap-beijing-1");
// 源bucket, bucket名需包含appid
String srcBucketName = "srcBucket-1251668577";
// 要拷贝的源文件
String srcKey = "aaa/bbb.txt";
// 目的bucket, bucket名需包含appid
String destBucketName = "destBucket-1251668577";
// 要拷贝的目的文件
String destKey = "ccc/ddd.txt";
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(srcBucketRegion, srcBucketName, srcKey, destBucketName, destKey);
try {
Copy copy = transferManager.copy(copyObjectRequest);
// 返回一个异步结果copy, 可同步的调用waitForCopyResult等待copy结束, 成功返回CopyResult, 失败抛出异常.
CopyResult copyResult = copy.waitForCopyResult();
System.out.println(copyResult.getCrc64Ecma());
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
transferManager.shutdownNow();
cosclient.shutdown();
}
use of com.qcloud.cos.model.CopyObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class TransferManagerDemo method copyFileForDiffRegion.
// copy接口支持根据文件大小自动选择copy或者分块copy
// 以下代码展示跨园区拷贝, 即将一个园区的文件拷贝到另一个园区
public static void copyFileForDiffRegion() {
// 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-beijing-1"));
// 3 生成cos客户端
COSClient cosclient = new COSClient(cred, clientConfig);
ExecutorService threadPool = Executors.newFixedThreadPool(32);
// 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
TransferManager transferManager = new TransferManager(cosclient, threadPool);
// 要拷贝的bucket region, 支持跨园区拷贝
Region srcBucketRegion = new Region("ap-shanghai");
// 源bucket, bucket名需包含appid
String srcBucketName = "srcBucket-1251668577";
// 要拷贝的源文件
String srcKey = "aaa/bbb.txt";
// 目的bucket, bucket名需包含appid
String destBucketName = "destBucket-1251668577";
// 要拷贝的目的文件
String destKey = "ccc/ddd.txt";
COSClient srcCOSClient = new COSClient(cred, new ClientConfig(srcBucketRegion));
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(srcBucketRegion, srcBucketName, srcKey, destBucketName, destKey);
try {
Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
// 返回一个异步结果copy, 可同步的调用waitForCopyResult等待copy结束, 成功返回CopyResult, 失败抛出异常.
CopyResult copyResult = copy.waitForCopyResult();
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
transferManager.shutdownNow();
srcCOSClient.shutdown();
cosclient.shutdown();
}
use of com.qcloud.cos.model.CopyObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutObjectCopyTest method testCopySameRegionDiffSize.
private void testCopySameRegionDiffSize(long fileSize, ObjectMetadata newObjectMetaData) throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File localFile = buildTestFile(fileSize);
String srcEtag = Md5Utils.md5Hex(localFile);
String srcKey = String.format("ut/src_len_%d.txt", fileSize);
String destKey = String.format("ut/dest_len_%d.txt", fileSize);
try {
PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, srcKey);
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucket, srcKey, bucket, destKey);
copyObjectRequest.setSourceVersionId(putObjectResult.getVersionId());
copyObjectRequest.setStorageClass(StorageClass.Standard_IA);
if (newObjectMetaData != null) {
copyObjectRequest.setNewObjectMetadata(newObjectMetaData);
}
CopyObjectResult copyObjectResult = cosclient.copyObject(copyObjectRequest);
assertNotNull(copyObjectResult.getRequestId());
assertNotNull(copyObjectResult.getDateStr());
// assertEquals(srcEtag, copyObjectResult.getETag());
headSimpleObject(srcKey, fileSize, srcEtag);
/*
ObjectMetadata destObjectMetadata = headSimpleObject(destKey, fileSize, srcEtag);
if (newObjectMetaData != null) {
checkMetaData(newObjectMetaData, destObjectMetadata);
}
*/
} finally {
// delete file on cos
clearObject(srcKey);
clearObject(destKey);
// delete local file
if (localFile.exists()) {
assertTrue(localFile.delete());
}
}
}
Aggregations