Search in sources :

Example 6 with PartSummary

use of com.aliyun.oss.model.PartSummary in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseListParts.

/**
 * Unmarshall list parts response body to part listing.
 */
@SuppressWarnings("unchecked")
public static PartListing parseListParts(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        PartListing partListing = new PartListing();
        partListing.setBucketName(root.getChildText("Bucket"));
        partListing.setKey(root.getChildText("Key"));
        partListing.setUploadId(root.getChildText("UploadId"));
        partListing.setStorageClass(root.getChildText("StorageClass"));
        partListing.setMaxParts(Integer.valueOf(root.getChildText("MaxParts")));
        partListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
        if (root.getChild("PartNumberMarker") != null) {
            String partNumberMarker = root.getChildText("PartNumberMarker");
            if (!isNullOrEmpty(partNumberMarker)) {
                partListing.setPartNumberMarker(Integer.valueOf(partNumberMarker));
            }
        }
        if (root.getChild("NextPartNumberMarker") != null) {
            String nextPartNumberMarker = root.getChildText("NextPartNumberMarker");
            if (!isNullOrEmpty(nextPartNumberMarker)) {
                partListing.setNextPartNumberMarker(Integer.valueOf(nextPartNumberMarker));
            }
        }
        List<Element> partElems = root.getChildren("Part");
        for (Element elem : partElems) {
            PartSummary ps = new PartSummary();
            ps.setPartNumber(Integer.valueOf(elem.getChildText("PartNumber")));
            ps.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
            ps.setETag(trimQuotes(elem.getChildText("ETag")));
            ps.setSize(Integer.valueOf(elem.getChildText("Size")));
            partListing.addPart(ps);
        }
        return partListing;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) PartListing(com.aliyun.oss.model.PartListing) PartSummary(com.aliyun.oss.model.PartSummary)

Aggregations

PartListing (com.aliyun.oss.model.PartListing)6 PartSummary (com.aliyun.oss.model.PartSummary)6 ListPartsRequest (com.aliyun.oss.model.ListPartsRequest)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 OSSException (com.aliyun.oss.OSSException)3 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)3 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)3 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)3 PartETag (com.aliyun.oss.model.PartETag)3 UploadPartRequest (com.aliyun.oss.model.UploadPartRequest)3 UploadPartResult (com.aliyun.oss.model.UploadPartResult)3 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 OSSObject (com.aliyun.oss.model.OSSObject)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 ListMultipartUploadsRequest (com.aliyun.oss.model.ListMultipartUploadsRequest)1 MultipartUpload (com.aliyun.oss.model.MultipartUpload)1 MultipartUploadListing (com.aliyun.oss.model.MultipartUploadListing)1 ParseException (java.text.ParseException)1