private static Object toggleEndian(VR vr, Object value, boolean toggleEndian) { return (toggleEndian && value instanceof byte[]) ? vr.toggleEndian((byte[]) value, true) : value; }
private byte[] getBytes() { byte[] b = bout.toByteArray(); return bigEndian ? vr.toggleEndian(b, false) : b; }
@Override public byte[] toBytes(VR vr, boolean bigEndian) throws IOException { if (length == -1) throw new UnsupportedOperationException(); if (length == 0) return ByteUtils.EMPTY_BYTES; InputStream in = openStream(); try { byte[] b = new byte[length]; StreamUtils.readFully(in, b, 0, b.length); if (this.bigEndian != bigEndian) { vr.toggleEndian(b, false); } return b; } finally { in.close(); } }
private void writeInlineBinary(VR vr, byte[] b, boolean bigEndian, boolean preserve) { if (bigEndian) b = vr.toggleEndian(b, preserve); gen.write("InlineBinary", encodeBase64(b)); }
if (v2 instanceof byte[] && ((byte[]) v1).length == ((byte[]) v2).length) { if (bigEndian != other.bigEndian) v2 = vr.toggleEndian((byte[]) v2, true); return Arrays.equals((byte[]) v1, (byte[]) v2);
private void writeAttribute(int tag, VR vr, Object value, SpecificCharacterSet cs, Attributes attrs) throws SAXException { if (TagUtils.isGroupLength(tag) || TagUtils.isPrivateCreator(tag)) return; String privateCreator = attrs.getPrivateCreator(tag); addAttributes(tag, vr, privateCreator); startElement("DicomAttribute"); if (value instanceof Value) writeAttribute((Value) value, attrs.bigEndian()); else if (!vr.isInlineBinary()) { writeValues(vr, value, attrs.bigEndian(), attrs.getSpecificCharacterSet(vr)); } else if (value instanceof byte[]) { writeInlineBinary(attrs.bigEndian() ? vr.toggleEndian((byte[]) value, true) : (byte[]) value); } else throw new IllegalArgumentException("vr: " + vr + ", value class: " + value.getClass()); endElement("DicomAttribute"); }
@Override public void readValue(DicomInputStream dis, Fragments frags) throws IOException { int len = dis.length(); if (dis.isExcludeBulkData()) { dis.skipFully(len); } else try { frags.add(ByteUtils.EMPTY_BYTES); // increment size if (len > 0) { startElement("DataFragment", "number", frags.size()); if (dis.isIncludeBulkDataURI()) { writeBulkData(dis.createBulkData(dis)); } else { byte[] b = dis.readValue(); if (dis.bigEndian()) frags.vr().toggleEndian(b, false); writeInlineBinary(b); } endElement("DataFragment"); } } catch (SAXException e) { throw new IOException(e); } }
@Override public void readValue(DicomInputStream dis, Fragments frags) throws IOException { checkIsThis(dis); if (excludeBulkData) { skipFully(length); } else if (length == 0) { frags.add(ByteUtils.EMPTY_BYTES); } else if (length == BulkData.MAGIC_LEN && super.in instanceof ObjectInputStream) { frags.add(BulkData.deserializeFrom((ObjectInputStream) super.in)); } else if (includeBulkDataURI) { frags.add(bulkDataCreator.createBulkData(this)); } else { byte[] b = readValue(); if (bigEndian != frags.bigEndian()) frags.vr().toggleEndian(b, false); frags.add(b); } }
byte[] b = (byte[]) frag; if (bigEndian) frags.vr().toggleEndian(b, true); writeInlineBinary(b);
@Override public void readValue(DicomInputStream dis, Attributes attrs) throws IOException { checkIsThis(dis); if (excludeBulkData) { skipFully(length); } else if (length == 0) { attrs.setNull(tag, vr); } else if (vr == VR.SQ) { readSequence(length, attrs, tag); } else if (length == -1) { readFragments(attrs, tag, vr); } else if (length == BulkData.MAGIC_LEN && super.in instanceof ObjectInputStream) { attrs.setValue(tag, vr, BulkData.deserializeFrom( (ObjectInputStream) super.in)); } else if (includeBulkDataURI) { attrs.setValue(tag, vr, bulkDataCreator.createBulkData(this)); } else { byte[] b = readValue(); if (!TagUtils.isGroupLength(tag)) { if (bigEndian != attrs.bigEndian()) vr.toggleEndian(b, false); attrs.setBytes(tag, vr, b); } else if (tag == Tag.FileMetaInformationGroupLength) setFileMetaInformationGroupLength(b); } }
if (vr.isInlineBinary()) writeInlineBinary(dis.bigEndian() ? vr.toggleEndian(b, false) : b); else