DicomOutputStream extends OutputStream { public DicomOutputStream writeFileMetaInformation(DicomObject fmi) throws IOException { if (encoding != null) throw new IllegalStateException("encoding already initialized: " + encoding); byte[] b = new byte[132]; b[128] = 'D'; b[129] = 'I'; b[130] = 'C'; b[131] = 'M'; write(b); encoding = DicomEncoding.EVR_LE; boolean includeGroupLength0 = includeGroupLength; try { includeGroupLength = true; ((DicomObjectImpl) fmi).calculateItemLength(this); ((DicomObjectImpl) fmi).writeTo(this); } finally { includeGroupLength = includeGroupLength0; } return 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 writeFileMetaInformation() throws IOException { DicomObject fmi = DicomObject.newDicomObject(); fmi.setString(Tag.TransferSyntaxUID, VR.UI, UID.DeflatedExplicitVRLittleEndian); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try (DicomOutputStream dos = new DicomOutputStream(bout)) { dos.writeFileMetaInformation(fmi) .withEncoding(fmi) .writeDataSet(DicomObject.newDicomObject()); } assertArrayEquals(resourceAsBytes("preamble_fmi_defl.dcm"), bout.toByteArray()); }