use of com.qcloud.cos.model.DeleteObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class PutGetDelTest method testRequestSpecifiedKeyInfoPutGetDel.
@Test
public void testRequestSpecifiedKeyInfoPutGetDel() throws CosServiceException, IOException, InterruptedException {
COSClient cosclient = new COSClient(new AnonymousCOSCredentials(), clientConfig);
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.DeleteObjectRequest in project cos-java-sdk-v5 by tencentyun.
the class COSEncryptionClient method deleteObject.
@Override
public void deleteObject(DeleteObjectRequest req) {
// Delete the object
super.deleteObject(req);
// If it exists, delete the instruction file.
InstructionFileId ifid = new COSObjectId(req.getBucketName(), req.getKey()).instructionFileId();
DeleteObjectRequest instructionDeleteRequest = (DeleteObjectRequest) req.clone();
instructionDeleteRequest.withBucketName(ifid.getBucket()).withKey(ifid.getKey());
super.deleteObject(instructionDeleteRequest);
}
use of com.qcloud.cos.model.DeleteObjectRequest in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method delete.
@Override
public void delete(String key) throws IOException {
LOG.debug("Delete the cos key: {} from bucket: {}.", key, this.bucketName);
try {
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, key);
callCOSClientWithRetry(deleteObjectRequest);
} catch (Exception e) {
String errMsg = String.format("Deleting the cos key [%s] occurs an exception: " + "%s", key, e);
handleException(new Exception(errMsg), key);
}
}
use of com.qcloud.cos.model.DeleteObjectRequest in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method deleteRecursive.
/**
* delete recursive only used on posix bucket to delete dir recursive
* @param key cos key
* @throws IOException e
*/
@Override
public void deleteRecursive(String key) throws IOException {
LOG.debug("Delete the cos key recursive: {} from bucket: {}.", key, this.bucketName);
try {
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, key);
deleteObjectRequest.setRecursive(true);
callCOSClientWithRetry(deleteObjectRequest);
} catch (Exception e) {
String errMsg = String.format("Deleting the cos key recursive [%s] occurs an exception: " + "%s", key, e);
handleException(new Exception(errMsg), key);
}
}
use of com.qcloud.cos.model.DeleteObjectRequest in project hadoop-cos by tencentyun.
the class CosNativeFileSystemStore method normalBucketRename.
public void normalBucketRename(String srcKey, String dstKey) throws IOException {
LOG.debug("Rename normal bucket key, the source cos key [{}] to the dest cos key [{}].", srcKey, dstKey);
try {
ObjectMetadata objectMetadata = new ObjectMetadata();
if (crc32cEnabled) {
objectMetadata.setHeader(Constants.CRC32C_REQ_HEADER, Constants.CRC32C_REQ_HEADER_VAL);
}
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, srcKey, bucketName, dstKey);
// get the storage class of the source file
FileMetadata sourceFileMetadata = this.retrieveMetadata(srcKey);
if (null != sourceFileMetadata.getStorageClass()) {
copyObjectRequest.setStorageClass(sourceFileMetadata.getStorageClass());
}
copyObjectRequest.setNewObjectMetadata(objectMetadata);
this.setEncryptionMetadata(copyObjectRequest, objectMetadata);
copyObjectRequest.setSourceEndpointBuilder(this.cosClient.getClientConfig().getEndpointBuilder());
callCOSClientWithRetry(copyObjectRequest);
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, srcKey);
callCOSClientWithRetry(deleteObjectRequest);
} catch (Exception e) {
String errMsg = String.format("Rename object failed, normal bucket, source cos key: %s, dest cos key: %s, " + "exception: %s", srcKey, dstKey, e);
handleException(new Exception(errMsg), srcKey);
}
}
Aggregations