DicomOutputStream extends OutputStream { public void writeCommandSet(DicomObject dcmobj) throws IOException { if (encoding != null) throw new IllegalStateException("encoding already initialized: " + encoding); Objects.requireNonNull(dcmobj); encoding = DicomEncoding.IVR_LE; includeGroupLength = true; ((DicomObjectImpl) dcmobj).calculateItemLength(this); ((DicomObjectImpl) dcmobj).writeTo(this); } DicomOutputStream(OutputStream out); DicomEncoding getEncoding(); DicomOutputStream withEncoding(DicomEncoding encoding); DicomOutputStream withEncoding(DicomObject fmi); boolean isIncludeGroupLength(); DicomOutputStream withIncludeGroupLength(boolean includeGroupLength); LengthEncoding getItemLengthEncoding(); DicomOutputStream withItemLengthEncoding(LengthEncoding itemLengthEncoding); LengthEncoding getSequenceLengthEncoding(); DicomOutputStream withSequenceLengthEncoding(LengthEncoding sequenceLengthEncoding); @Override void write(int b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close(); void writeHeader(int tag, VR vr, int length); DicomOutputStream writeFileMetaInformation(DicomObject fmi); void writeDataSet(DicomObject dcmobj); void writeCommandSet(DicomObject dcmobj); byte[] swapBuffer(); void writeUTF(String s);  }
@Test void writeCommandSet() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try (DicomOutputStream dos = new DicomOutputStream(bout)) { dos.writeCommandSet(c_echo_rq()); } assertArrayEquals(C_ECHO_RQ, bout.toByteArray()); }