use of com.qcloud.cos.internal.DeleteObjectsResponse in project cos-java-sdk-v5 by tencentyun.
the class COSClient method deleteObjects.
@Override
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) throws MultiObjectDeleteException, CosClientException, CosServiceException {
rejectNull(deleteObjectsRequest, "The DeleteObjectsRequest parameter must be specified when deleting objects");
rejectNull(clientConfig.getRegion(), "region is null, region in clientConfig must be specified when deleting objects");
CosHttpRequest<DeleteObjectsRequest> request = createRequest(deleteObjectsRequest.getBucketName(), null, deleteObjectsRequest, HttpMethodName.POST);
request.addParameter("delete", null);
byte[] content = new MultiObjectDeleteXmlFactory().convertToXmlByteArray(deleteObjectsRequest);
request.addHeader("Content-Length", String.valueOf(content.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(content));
try {
byte[] md5 = Md5Utils.computeMD5Hash(content);
String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch (Exception e) {
throw new CosClientException("Couldn't compute md5 sum", e);
}
@SuppressWarnings("unchecked") ResponseHeaderHandlerChain<DeleteObjectsResponse> responseHandler = new ResponseHeaderHandlerChain<DeleteObjectsResponse>(new Unmarshallers.DeleteObjectsResultUnmarshaller());
DeleteObjectsResponse response = invoke(request, responseHandler);
/*
* If the result was only partially successful, throw an exception
*/
if (!response.getErrors().isEmpty()) {
Map<String, String> headers = responseHandler.getResponseHeaders();
MultiObjectDeleteException ex = new MultiObjectDeleteException(response.getErrors(), response.getDeletedObjects());
ex.setStatusCode(200);
ex.setRequestId(headers.get(Headers.REQUEST_ID));
throw ex;
}
DeleteObjectsResult result = new DeleteObjectsResult(response.getDeletedObjects());
return result;
}
Aggregations