public void writeGroupLength(int tag, int len) throws IOException { byte[] b = buf; ByteUtils.tagToBytes(tag, b, 0, bigEndian); if (explicitVR) { ByteUtils.shortToBytesBE(VR.UL.code(), b, 4); ByteUtils.shortToBytes(4, b, 6, bigEndian); } else { ByteUtils.intToBytes(4, b, 4, bigEndian); } ByteUtils.intToBytes(len, b, 8, bigEndian); out.write(b, 0, 12); }
public void writeHeader(int tag, VR vr, int len) throws IOException { byte[] b = buf; ByteUtils.tagToBytes(tag, b, 0, bigEndian); int headerLen; if (!TagUtils.isItem(tag) && explicitVR) { ByteUtils.shortToBytesBE(vr.code(), b, 4); if ((headerLen = vr.headerLength()) == 8) { ByteUtils.shortToBytes(len, b, 6, bigEndian); } else { b[6] = b[7] = 0; ByteUtils.intToBytes(len, b, 8, bigEndian); } } else { ByteUtils.intToBytes(len, b, 4, bigEndian); headerLen = 8; } out.write(b, 0, headerLen); }
private boolean guessTransferSyntax(byte[] b128, int rlen, boolean bigEndian) throws DicomStreamException { int tag1 = ByteUtils.bytesToTag(b128, 0, bigEndian); VR vr = ElementDictionary.vrOf(tag1, null); if (vr == VR.UN) return false; if (ByteUtils.bytesToVR(b128, 4) == vr.code()) { this.tsuid = bigEndian ? UID.ExplicitVRBigEndianRetired : UID.ExplicitVRLittleEndian; this.bigEndian = bigEndian; this.explicitVR = true; return true; } int len = ByteUtils.bytesToInt(b128, 4, bigEndian); if (len < 0 || 8 + len > rlen) return false; if (bigEndian) throw new DicomStreamException(IMPLICIT_VR_BIG_ENDIAN); this.tsuid = UID.ImplicitVRLittleEndian; this.bigEndian = false; this.explicitVR = false; return true; } }