Class DicomOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class DicomOutputStream
    extends BinaryOutputStream

    A class that extends BinaryOutputStream by adding the concept of transfer syntaxes, for a (possible) meta information header and a data set.

    Note this class does not automatically switch from meta information header to data set transfer syntaxes. That is the responsibility of the caller writing the individual attributes (such as by reaching the end of the meta information group length, and then calling setWritingDataSet().

    See Also:
    AttributeList, DicomInputStream
    • Constructor Detail

      • DicomOutputStream

        public DicomOutputStream​(java.io.OutputStream o,
                                 java.lang.String metaTransferSyntaxUID,
                                 java.lang.String dataTransferSyntaxUID)
                          throws java.io.IOException

        Construct a stream to write DICOM data sets to the supplied stream.

        If the metaTransferSyntaxUID is not null, a 128 byte preamble of all zeroes plus "DICM" will also be written.

        Parameters:
        o - the output stream to write to
        metaTransferSyntaxUID - use this transfer syntax for the meta information header (may be null)
        dataTransferSyntaxUID - use this transfer syntax for the data set
        Throws:
        java.io.IOException - if an I/O error occurs
      • DicomOutputStream

        public DicomOutputStream​(java.io.OutputStream o,
                                 java.lang.String metaTransferSyntaxUID,
                                 java.lang.String dataTransferSyntaxUID,
                                 byte[] preamble)
                          throws java.io.IOException

        Construct a stream to write DICOM data sets to the supplied stream.

        If the metaTransferSyntaxUID is not null, a 128 byte preamble plus "DICM" will also be written.

        Parameters:
        o - the output stream to write to
        metaTransferSyntaxUID - use this transfer syntax for the meta information header (may be null)
        dataTransferSyntaxUID - use this transfer syntax for the data set
        preamble - 128 bytes to use as preamble, otherwise null to use default of all zero bytes
        Throws:
        java.io.IOException - if an I/O error occurs
    • Method Detail

      • setTransferSyntaxToWriteDataSet

        public void setTransferSyntaxToWriteDataSet​(TransferSyntax ts)

        Specify what transfer syntax to use when switching from writing the meta information header to writing the data set.

        Parameters:
        ts - transfer syntax to use for data set
      • setWritingDataSet

        public void setWritingDataSet()

        Switch to the transfer syntax for writing the dataset.

      • areWritingDataSet

        public boolean areWritingDataSet()

        Are we writing the dataset?

        Returns:
        true if writing the dataset, false if reading the meta information header
      • setWritingMetaHeader

        public void setWritingMetaHeader()

        Switch to the transfer syntax for writing the meta information header.

      • areWritingMetaHeader

        public boolean areWritingMetaHeader()

        Are we writing the meta information header?

        Returns:
        true if writing the meta information header, false if writing the dataset
      • haveMetaHeader

        public boolean haveMetaHeader()

        Will we be writing a meta information header?

        Returns:
        true if there is a meta information header, false if not
      • getTransferSyntaxInUse

        public TransferSyntax getTransferSyntaxInUse()

        Get the transfer syntax currently in use.

        Returns:
        the transfer syntax
      • getTransferSyntaxToWriteDataSet

        public TransferSyntax getTransferSyntaxToWriteDataSet()

        Get the transfer syntax to be used for writing the data set.

        Returns:
        the transfer syntax
      • getTransferSyntaxToWriteMetaHeader

        public TransferSyntax getTransferSyntaxToWriteMetaHeader()

        Get the transfer syntax to be used for writing the meta information header.

        Returns:
        the transfer syntax
      • getByteOffsetOfStartOfData

        public long getByteOffsetOfStartOfData()

        Get the byte offset of the start of the dataset or meta information header.

        Will be 0 if no preamble, 132 if a preamble.

        Returns:
        the byte offset (from 0 being the start of the stream)
      • isExplicitVR

        public boolean isExplicitVR()

        Is the transfer syntax currently in use explicit VR ?

        Returns:
        true if explicit VR, false if implicit VR
      • isImplicitVR

        public boolean isImplicitVR()

        Is the transfer syntax currently in use implicit VR ?

        Returns:
        true if implicit VR, false if explicit VR