/** * Converts the specified list of PartETags to an XML fragment that can be sent to the * CompleteMultipartUpload operation of Amazon S3. * * @param partETags The list of part ETags containing the data to include in the new XML fragment. * @return A byte array containing the data */ public static byte[] convertToXmlByteArray(List<PartETag> partETags) { XmlWriter xml = new XmlWriter(); xml.start("CompleteMultipartUpload"); if (partETags != null) { List<PartETag> sortedPartETags = new ArrayList<PartETag>(partETags); Collections.sort( sortedPartETags, new Comparator<PartETag>() { public int compare(PartETag tag1, PartETag tag2) { if (tag1.getPartNumber() < tag2.getPartNumber()) return -1; if (tag1.getPartNumber() > tag2.getPartNumber()) return 1; return 0; } }); for (PartETag partEtag : sortedPartETags) { xml.start("Part"); xml.start("PartNumber").value(Integer.toString(partEtag.getPartNumber())).end(); xml.start("ETag").value(partEtag.getETag()).end(); xml.end(); } } xml.end(); return xml.getBytes(); }
public static void xs3_coplete_multi_upload(String xs3_objname, String uploadId) { AWSCredentials xs3_credentials = new BasicAWSCredentials(xs3_access_key, xs3_secret_key); ClientConfiguration xs3_clientconfig = new ClientConfiguration(); xs3_clientconfig.setProtocol(Protocol.HTTP); S3ClientOptions xs3_client_options = new S3ClientOptions(); xs3_client_options.setPathStyleAccess(true); xs3_client = new AmazonS3Client(xs3_credentials, xs3_clientconfig); xs3_client.setEndpoint(xs3_endpoint); xs3_client.setS3ClientOptions(xs3_client_options); try { List<PartETag> rest_parts = listPartsXml(xs3_objname, uploadId); if (null == rest_parts) { return; } for (PartETag item : rest_parts) { System.out.println(item.getETag() + " -> " + item.getPartNumber()); } CompleteMultipartUploadRequest comp_req = new CompleteMultipartUploadRequest(xs3_bucketname, xs3_objname, uploadId, rest_parts); CompleteMultipartUploadResult comp_result = xs3_client.completeMultipartUpload(comp_req); System.out.println(comp_result.getETag()); System.out.println(comp_result.getKey()); } catch (AmazonServiceException ase) { System.out.println("xs3_svr_error_message:" + ase.getMessage()); System.out.println("xs3_svr_status_code: " + ase.getStatusCode()); System.out.println("xs3_svr_error_code: " + ase.getErrorCode()); System.out.println("xs3_svr_error_type: " + ase.getErrorType()); System.out.println("xs3_svr_request_id: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("xs3_clt_error_message:" + ace.getMessage()); } }