/** Unmarshall object metadata from response headers. */ public static ObjectMetadata parseObjectMetadata(Map<String, String> headers) throws IOException { try { ObjectMetadata objectMetadata = new ObjectMetadata(); for (Iterator<String> it = headers.keySet().iterator(); it.hasNext(); ) { String key = it.next(); if (key.indexOf(OSSHeaders.OSS_USER_METADATA_PREFIX) >= 0) { objectMetadata.addUserMetadata(key, headers.get(key)); } else if (key.equals(OSSHeaders.LAST_MODIFIED) || key.equals(OSSHeaders.DATE)) { try { objectMetadata.setHeader(key, DateUtil.parseRfc822Date(headers.get(key))); } catch (ParseException pe) { throw new IOException(pe.getMessage(), pe); } } else if (key.equals(OSSHeaders.CONTENT_LENGTH)) { Long value = Long.valueOf(headers.get(key)); objectMetadata.setHeader(key, value); } else if (key.equals(OSSHeaders.ETAG)) { objectMetadata.setHeader(key, trimQuotes(headers.get(key))); } else { objectMetadata.setHeader(key, headers.get(key)); } } return objectMetadata; } catch (Exception e) { throw new IOException(e.getMessage(), e); } }
/** * 解析XML中的Contents * * @param list * @return */ private static OSSObjectSummary parseObjectSummaryXML(NodeList list) throws ParseException { OSSObjectSummary object = new OSSObjectSummary(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("Key")) { object.setKey(checkChildNotNullAndGetValue(item)); } else if (name.equals("LastModified")) { object.setLastModified(DateUtil.parseIso8601Date(checkChildNotNullAndGetValue(item))); } else if (name.equals("Size")) { String size = checkChildNotNullAndGetValue(item); if (size != null) { object.setSize(Integer.valueOf(size)); } } else if (name.equals("ETag")) { object.setETag(checkChildNotNullAndGetValue(item)); } else if (name.equals("Type")) { object.setType(checkChildNotNullAndGetValue(item)); } else if (name.equals("StorageClass")) { object.setStorageClass(checkChildNotNullAndGetValue(item)); } } return object; }
private static CopyObjectResult parseCopyObjectResponseXML(InputStream in) throws ParseException, ParserConfigurationException, IOException, SAXException { CopyObjectResult result = new CopyObjectResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[item] - " + element.getNodeName()); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("LastModified")) { result.setLastModified(DateUtil.parseIso8601Date(checkChildNotNullAndGetValue(item))); } else if (name.equals("ETag")) { result.setEtag(checkChildNotNullAndGetValue(item)); } } return result; }
private static ListPartsResult parseListPartsResponseXML(InputStream in) throws ParserConfigurationException, IOException, SAXException, ParseException { ListPartsResult result = new ListPartsResult(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dom = builder.parse(in); Element element = dom.getDocumentElement(); OSSLog.logD("[parseObjectListResponse] - " + element.getNodeName()); List<PartSummary> partEtagList = new ArrayList<PartSummary>(); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node item = list.item(i); String name = item.getNodeName(); if (name == null) { continue; } else if (name.equals("Bucket")) { result.setBucketName(checkChildNotNullAndGetValue(item)); } else if (name.equals("Key")) { result.setKey(checkChildNotNullAndGetValue(item)); } else if (name.equals("UploadId")) { result.setUploadId(checkChildNotNullAndGetValue(item)); } else if (name.equals("PartNumberMarker")) { String partNumberMarker = checkChildNotNullAndGetValue(item); if (partNumberMarker != null) { result.setPartNumberMarker(Integer.valueOf(partNumberMarker)); } } else if (name.equals("NextPartNumberMarker")) { String nextPartNumberMarker = checkChildNotNullAndGetValue(item); if (nextPartNumberMarker != null) { result.setNextPartNumberMarker(Integer.valueOf(nextPartNumberMarker)); } } else if (name.equals("MaxParts")) { String maxParts = checkChildNotNullAndGetValue(item); if (maxParts != null) { result.setMaxParts(Integer.valueOf(maxParts)); } } else if (name.equals("IsTruncated")) { String isTruncated = checkChildNotNullAndGetValue(item); if (isTruncated != null) { result.setTruncated(Boolean.valueOf(isTruncated)); } } else if (name.equals("Part")) { NodeList partNodeList = item.getChildNodes(); PartSummary partSummary = new PartSummary(); for (int k = 0; k < partNodeList.getLength(); k++) { Node partItem = partNodeList.item(k); String partItemName = partItem.getNodeName(); if (partItemName == null) { continue; } else if (partItemName.equals("PartNumber")) { String partNumber = checkChildNotNullAndGetValue(partItem); if (partNumber != null) { partSummary.setPartNumber(Integer.valueOf(partNumber)); } } else if (partItemName.equals("LastModified")) { partSummary.setLastModified( DateUtil.parseIso8601Date(checkChildNotNullAndGetValue(partItem))); } else if (partItemName.equals("ETag")) { partSummary.setETag(checkChildNotNullAndGetValue(partItem)); } else if (partItemName.equals("Size")) { String size = checkChildNotNullAndGetValue(partItem); if (size != null) { partSummary.setSize(Integer.valueOf(size)); } } } partEtagList.add(partSummary); } } result.setParts(partEtagList); return result; }