private void writeFragment(VR vr, byte[] bytes, boolean bigEndian, String fpath) throws SAXException, IOException { startItemElement(-1, (bytes.length + 1) & ~1, fpath); if (fpath != null) { writeToFile(bytes); } else { vr.formatXMLValue(bytes, bigEndian, null, cbuf, ch); } endItemElement(); }
private String fpath(int tag, VR vr, int vallen) { return !exclude(tag, vr, vallen) ? null : file == null ? "" : file.getPath().substring(baseOff) .replace(File.separatorChar, '/'); }
public void write(DicomObject attrs) throws SAXException, IOException { ch.startDocument(); file = baseDir; writeContent(attrs, attrs.isRoot() ? TAG_DICOM : TAG_ITEM); ch.endDocument(); }
private void writeElement(DicomObject attrs, DicomElement a) throws SAXException, IOException { VR vr = a.vr(); final int tag = a.tag(); if (file != null) file = new File(file, StringUtils.intToHex(tag)); String fpath = fpath(tag, vr, a.length()); startAttributeElement(tag, vr, a.length(), fpath, attrs); if (a.hasItems()) { for (int i = 0, n = a.countItems(); i < n; ++i) { writeItem(a, i); } } else { if (fpath != null) { writeToFile(a.getBytes()); } else { vr.formatXMLValue(a.getBytes(), a.bigEndian(), attrs.getSpecificCharacterSet(), cbuf, ch); } } endAttributeElement(); if (file != null) file = file.getParentFile(); }
private void transcodeItem(DicomInputStream in) throws SAXException, IOException { final DicomElement sq = in.sq(); final int itemLen = in.valueLength(); final VR sqvr = sq.vr(); final int index = sq.countItems(); if (file != null) file = new File(file, Integer.toString(index+1)); final String fpath = fpath(sq.tag(), sqvr, itemLen); startItemElement(in.tagPosition(), itemLen, fpath); in.readValue(in); if (sq.hasFragments() && index < sq.countItems()) { byte[] data = sq.getFragment(index); if (fpath != null) { writeToFile(data); } else { final boolean bigEndian = in.getTransferSyntax().bigEndian(); sqvr.formatXMLValue(data, bigEndian, null, cbuf, ch); } sq.setFragment(index, EMPTY_BYTES); // allow gc to release byte[] } endItemElement(); if (file != null) file = file.getParentFile(); }
private void writeItem(DicomElement a, int index) throws SAXException, IOException { if (file != null) file = new File(file, Integer.toString(index+1)); if (a.vr() == VR.SQ) { writeContent(a.getDicomObject(index), TAG_ITEM); } else { final byte[] data = a.getFragment(index); writeFragment(a.vr(), data, a.bigEndian(), fpath(a.tag(), a.vr(), data.length)); } if (file != null) file = file.getParentFile(); }
ch.startDocument(); transcodeItem(in); if (isRoot) ch.endDocument(); ch.startElement("", TAG_DICOM, TAG_DICOM, new AttributesImpl()); transcodeAttribute(in);
private void writeContent(DicomObject attrs, String qName) throws SAXException, IOException { AttributesImpl atts = new AttributesImpl(); if (!attrs.isRoot()) { atts.addAttribute("", ATTR_OFF, ATTR_OFF, "", Long.toString(attrs.getItemOffset())); } ch.startElement("", qName, qName, new AttributesImpl()); for (Iterator<DicomElement> it = attrs.iterator(); it.hasNext();) { writeElement(attrs, it.next()); } ch.endElement("", qName, qName); }
if (file != null) file = new File(file, tagHex); final String fpath = fpath(tag, vr, vallen); startAttributeElement(tag, vr, vallen, fpath, attrs); if (vallen == -1 || vr == VR.SQ) { in.readValue(in); final boolean bigEndian = in.getTransferSyntax().bigEndian(); if (fpath != null) { writeToFile(val); } else { vr.formatXMLValue(val, bigEndian, endAttributeElement();