use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.
the class AbstractCOSClientTest method putObjectFromLocalFileByInputStream.
protected static void putObjectFromLocalFileByInputStream(File localFile, long uploadSize, String uploadEtag, String key, ObjectMetadata objectMetadata) {
if (!judgeUserInfoValid()) {
return;
}
FileInputStream input = null;
try {
input = new FileInputStream(localFile);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, input, objectMetadata);
putObjectRequest.setStorageClass(StorageClass.Standard_IA);
PutObjectResult putObjectResult = cosclient.putObject(putObjectRequest);
String etag = putObjectResult.getETag();
if (useClientEncryption) {
assertEquals(false, uploadEtag.equals(etag));
} else {
assertEquals(true, uploadEtag.equals(etag));
}
} catch (IOException e) {
fail(e.toString());
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
}
}
}
}
use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.
the class ListVersionsTest method putTestFile.
public void putTestFile(boolean retVersionFlag) throws Exception {
for (int i = 0; i < fileNum; ++i) {
for (int j = 0; j < eachFileVersionNum; ++j) {
long localFileSize = (i + 1) * 1024L;
String key = String.format("%s/%06dk", keyPrefix, i);
File localFile = buildTestFile(localFileSize);
localFileArray[i * eachFileVersionNum + j] = localFile;
keyArray[i * eachFileVersionNum + j] = key;
PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
if (retVersionFlag) {
assertNotNull("put object for version enalbed bucket should return versonId", putObjectResult.getVersionId());
} else {
assertEquals(null, putObjectResult.getVersionId());
}
}
}
}
use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.
the class UploadCallable method uploadInOneChunk.
/**
* Uploads the given request in a single chunk and returns the result.
*/
private UploadResult uploadInOneChunk() {
PutObjectResult putObjectResult = cos.putObject(origReq);
UploadResult uploadResult = new UploadResult();
uploadResult.setBucketName(origReq.getBucketName());
uploadResult.setKey(origReq.getKey());
uploadResult.setETag(putObjectResult.getETag());
uploadResult.setVersionId(putObjectResult.getVersionId());
uploadResult.setRequestId(putObjectResult.getRequestId());
uploadResult.setDateStr(putObjectResult.getDateStr());
uploadResult.setCrc64Ecma(putObjectResult.getCrc64Ecma());
uploadResult.setCiUploadResult(putObjectResult.getCiUploadResult());
return uploadResult;
}
use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method putObjectFromString.
private void putObjectFromString(String key, String content) throws IOException {
if (!judgeUserInfoValid()) {
return;
}
File downloadFile = buildTestFile(0L);
try {
String contentEtag = Md5Utils.md5Hex(content);
PutObjectResult putObjectResult = cosclient.putObject(bucket, key, content);
String etag = putObjectResult.getETag();
assertEquals(!useClientEncryption, contentEtag.equals(etag));
headSimpleObject(key, content.getBytes(StringUtils.UTF8).length, contentEtag);
getObject(key, downloadFile, null, content.getBytes(StringUtils.UTF8).length, contentEtag);
cosclient.getObjectMetadata(bucket, key);
} finally {
cosclient.deleteObject(bucket, key);
assertTrue(downloadFile.delete());
}
}
use of com.qcloud.cos.model.PutObjectResult in project cos-java-sdk-v5 by tencentyun.
the class BatchDeleteTest method batchDeleteAllExistFileForVersionEnabled.
@Test
public void batchDeleteAllExistFileForVersionEnabled() throws IOException, InterruptedException {
if (!judgeUserInfoValid()) {
return;
}
BucketVersioningConfiguration bucketVersioningEnabled = new BucketVersioningConfiguration(BucketVersioningConfiguration.ENABLED);
cosclient.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(bucket, bucketVersioningEnabled));
Thread.sleep(5000L);
DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucket);
ArrayList<KeyVersion> keyList = new ArrayList<>();
long deleteFileCount = 30;
for (long fileIndex = 0; fileIndex < deleteFileCount; ++fileIndex) {
File localFile = buildTestFile(fileIndex * 1024);
String key = "ut/" + localFile.getName();
PutObjectResult putObjectResult = putObjectFromLocalFile(localFile, key);
keyList.add(new KeyVersion(key, putObjectResult.getVersionId()));
}
deleteObjectsRequest.setKeys(keyList);
DeleteObjectsResult deleteObjectsResult = cosclient.deleteObjects(deleteObjectsRequest);
assertEquals(deleteFileCount, deleteObjectsResult.getDeletedObjects().size());
}
Aggregations