use of com.amazonaws.services.s3.model.transform.MultiObjectDeleteXmlFactory in project aws-sdk-android by aws-amplify.
the class AmazonS3Client method deleteObjects.
/*
* (non-Javadoc)
* @see
* com.amazonaws.services.s3.AmazonS3#deleteObjects(com.amazonaws.services
* .s3.model.DeleteObjectsRequest)
*/
@Override
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) {
final Request<DeleteObjectsRequest> request = createRequest(deleteObjectsRequest.getBucketName(), null, deleteObjectsRequest, HttpMethodName.POST);
request.addParameter("delete", null);
if (deleteObjectsRequest.getMfa() != null) {
populateRequestWithMfaDetails(request, deleteObjectsRequest.getMfa());
}
populateRequesterPaysHeader(request, deleteObjectsRequest.isRequesterPays());
final 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 {
final byte[] md5 = Md5Utils.computeMD5Hash(content);
final String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch (final Exception e) {
throw new AmazonClientException("Couldn't compute md5 sum", e);
}
@SuppressWarnings("unchecked") final ResponseHeaderHandlerChain<DeleteObjectsResponse> responseHandler = new ResponseHeaderHandlerChain<DeleteObjectsResponse>(new Unmarshallers.DeleteObjectsResultUnmarshaller(), new S3RequesterChargedHeaderHandler<DeleteObjectsResponse>());
final DeleteObjectsResponse response = invoke(request, responseHandler, deleteObjectsRequest.getBucketName(), null);
/*
* If the result was only partially successful, throw an exception
*/
if (!response.getErrors().isEmpty()) {
final Map<String, String> headers = responseHandler.getResponseHeaders();
final MultiObjectDeleteException ex = new MultiObjectDeleteException(response.getErrors(), response.getDeletedObjects());
ex.setStatusCode(200);
ex.setRequestId(headers.get(Headers.REQUEST_ID));
ex.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
ex.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
throw ex;
}
final DeleteObjectsResult result = new DeleteObjectsResult(response.getDeletedObjects(), response.isRequesterCharged());
return result;
}
Aggregations