Search in sources :

Example 1 with DeleteObjectRequest

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();
    }
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) File(java.io.File) GetObjectRequest(com.qcloud.cos.model.GetObjectRequest) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) Test(org.junit.Test)

Example 2 with DeleteObjectRequest

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);
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) COSObjectId(com.qcloud.cos.model.COSObjectId) InstructionFileId(com.qcloud.cos.model.InstructionFileId)

Example 3 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) ResponseNotCompleteException(com.qcloud.cos.exception.ResponseNotCompleteException) CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) IOException(java.io.IOException)

Example 4 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) ResponseNotCompleteException(com.qcloud.cos.exception.ResponseNotCompleteException) CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) IOException(java.io.IOException)

Example 5 with DeleteObjectRequest

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);
    }
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) CopyObjectRequest(com.qcloud.cos.model.CopyObjectRequest) ObjectMetadata(com.qcloud.cos.model.ObjectMetadata) ResponseNotCompleteException(com.qcloud.cos.exception.ResponseNotCompleteException) CosServiceException(com.qcloud.cos.exception.CosServiceException) CosClientException(com.qcloud.cos.exception.CosClientException) IOException(java.io.IOException)

Aggregations

DeleteObjectRequest (com.qcloud.cos.model.DeleteObjectRequest)7 CosClientException (com.qcloud.cos.exception.CosClientException)4 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ResponseNotCompleteException (com.qcloud.cos.exception.ResponseNotCompleteException)4 IOException (java.io.IOException)4 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)3 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)3 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)2 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)2 COSCredentials (com.qcloud.cos.auth.COSCredentials)2 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)2 File (java.io.File)2 Test (org.junit.Test)2 AbortMultipartUploadRequest (com.qcloud.cos.model.AbortMultipartUploadRequest)1 COSObject (com.qcloud.cos.model.COSObject)1 COSObjectId (com.qcloud.cos.model.COSObjectId)1 CompleteMultipartUploadRequest (com.qcloud.cos.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.qcloud.cos.model.CompleteMultipartUploadResult)1 CopyPartRequest (com.qcloud.cos.model.CopyPartRequest)1 GetObjectMetadataRequest (com.qcloud.cos.model.GetObjectMetadataRequest)1