public void writeFileMetaInformation(DicomObject attrs) throws IOException { if (preamble != null) { write(preamble, 0, PREAMBLE_LENGTH); write('D'); write('I'); write('C'); write('M'); } this.ts = TransferSyntax.ExplicitVRLittleEndian; writeElements(attrs.fileMetaInfoIterator(), true, new ItemInfo(attrs .fileMetaInfoIterator(), true)); }
/** * Write the given image as a byte array to the sequence. */ public void writeBytesToSequence(byte[] data, ImageWriteParam param) throws IOException { if (encapsulated) { dos.writeHeader(Tag.Item, null, (data.length+1) & ~1); } dos.write(data); if ((data.length & 1) != 0) dos.write(0); // The flush allows any memory buffer to be cleared. dos.flush(); ((ImageOutputStream) output).flush(); }
private void transcodeValue(DicomInputStream in, VR vr) throws IOException { boolean toggleEndian = out.getTransferSyntax().bigEndian() != in.getTransferSyntax().bigEndian(); int remaining = in.valueLength(); while (remaining > 0) { int len = Math.min(remaining, buf.length); in.readFully(buf, 0, len); if (toggleEndian) vr.toggleEndian(buf, 0, len); out.write(buf, 0, len); remaining -= len; } }
private void writeGroupLength(int tag, int length) throws IOException { writeHeader(tag, VR.UL, 4); write(VR.UL.toBytes(length, ts.bigEndian()), 0, 4); }
private void transcodeAttribute(DicomInputStream in) throws IOException { final int tag = in.tag(); final VR vr = in.vr(); final int vallen = in.valueLength(); final DicomObject attrs = in.getDicomObject(); if (vallen == -1 || vr == VR.SQ) { out.writeHeader(tag, vr, -1); TransferSyntax prevTS = out.getTransferSyntax(); if (vr == VR.UN) { out.setTransferSyntax(TransferSyntax.ImplicitVRLittleEndian); } in.readValue(in); attrs.remove(tag); out.writeHeader(Tag.SequenceDelimitationItem, null, 0); out.setTransferSyntax(prevTS); } else if (!TagUtils.isGroupLengthElement(tag)) { out.writeHeader(tag, vr, vallen); if (tag == Tag.SpecificCharacterSet || TagUtils.isPrivateCreatorDataElement(tag)) { byte[] val = in.readBytes(vallen); boolean bigEndian = in.getTransferSyntax().bigEndian(); attrs.putBytes(tag, vr, val, bigEndian); out.write(val); } else { transcodeValue(in, vr); } } }