use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testGetObjectIfMatchContainRightEtag.
@Ignore
public void testGetObjectIfMatchContainRightEtag() throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File localFile = buildTestFile(1024);
String key = "ut/" + localFile.getName();
cosclient.putObject(bucket, key, localFile);
try {
String fileEtag = Md5Utils.md5Hex(localFile);
String wrongEtag = fileEtag.substring(5) + fileEtag.substring(0, 5);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
List<String> eTagList = new ArrayList<>();
eTagList.add("\"" + wrongEtag + "\"");
eTagList.add("\"" + fileEtag + "\"");
getObjectRequest.setMatchingETagConstraints(eTagList);
COSObject cosObject = cosclient.getObject(getObjectRequest);
assertNotNull(cosObject);
} catch (CosServiceException cse) {
fail(cse.toString());
} finally {
cosclient.deleteObject(bucket, key);
assertTrue(localFile.delete());
}
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testRequestSpecifiedTmpKeyInfoPutGetDel.
@Test
public void testRequestSpecifiedTmpKeyInfoPutGetDel() throws CosServiceException, IOException, InterruptedException {
COSClient cosclient = buildTemporyCredentialsCOSClient(1800L);
File localFile = buildTestFile(1024L);
COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
try {
String key = "ut/request-specified-key";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
putObjectRequest.setCosCredentials(cosCredentials);
cosclient.putObject(putObjectRequest);
GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
getObjectRequest.setCosCredentials(cosCredentials);
cosclient.getObject(getObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, key);
deleteObjectRequest.setCosCredentials(cosCredentials);
cosclient.deleteObject(deleteObjectRequest);
} finally {
localFile.delete();
cosclient.shutdown();
}
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class KMSEncryptionClientDemo method transferManagerDemo.
static void transferManagerDemo() {
ExecutorService threadPool = Executors.newFixedThreadPool(32);
// 传入一个threadpool, 若不传入线程池, 默认TransferManager中会生成一个单线程的线程池。
TransferManager transferManager = new TransferManager(cosClient, threadPool);
TransferManagerConfiguration transferManagerConfiguration = new TransferManagerConfiguration();
transferManagerConfiguration.setMultipartUploadThreshold(1024 * 1024);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, bigLocalFile);
try {
// 返回一个异步结果Upload, 可同步的调用waitForUploadResult等待upload结束, 成功返回UploadResult, 失败抛出异常.
Upload upload = transferManager.upload(putObjectRequest);
UploadResult uploadResult = upload.waitForUploadResult();
System.out.println(uploadResult.getRequestId());
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
try {
// 返回一个异步结果Upload, 可同步的调用waitForUploadResult等待download结束, 成功返回DownloadResult, 失败抛出异常.
Download download = transferManager.download(getObjectRequest, new File("downLen10m.txt"));
download.waitForCompletion();
System.out.println(download.getObjectMetadata().getRequestId());
} catch (CosServiceException e) {
e.printStackTrace();
} catch (CosClientException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
transferManager.shutdownNow();
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class KMSEncryptionClientDemo method getObjectDemo.
static void getObjectDemo() {
// 下载文件
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
File downloadFile = new File("downlen1m.txt");
ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
System.out.println(objectMetadata.getRequestId());
}
use of com.qcloud.cos.model.GetObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class AsymmetricKeyEncryptionClientDemo method getObjectDemo.
static void getObjectDemo() {
// 下载文件
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
File downloadFile = new File("downAsy.txt");
ObjectMetadata objectMetadata = cosClient.getObject(getObjectRequest, downloadFile);
System.out.println(objectMetadata.getRequestId());
}
Aggregations