Class DicomInputStream

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

    public class DicomInputStream
    extends BinaryInputStream

    A class that extends BinaryInputStream 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 parsing the individual attributes (such as by reaching the end of the meta information group length, and then calling setReadingDataSet().

    See Also:
    AttributeList, DicomOutputStream
    • Constructor Detail

      • DicomInputStream

        public DicomInputStream​(java.io.InputStream i)
                         throws java.io.IOException

        Construct a stream to read DICOM data sets from the supplied stream.

        Look for a meta information header; if absent guess at a transfer syntax based on the contents.

        Parameters:
        i - the input stream to read from
        Throws:
        java.io.IOException - if an I/O error occurs
      • DicomInputStream

        public DicomInputStream​(java.io.File file)
                         throws java.io.IOException

        Construct a stream to read DICOM data sets from the supplied stream.

        Look for a meta information header; if absent guess at a transfer syntax based on the contents.

        Parameters:
        file - the file to read from
        Throws:
        java.io.IOException - if an I/O error occurs
      • DicomInputStream

        public DicomInputStream​(java.io.InputStream i,
                                java.lang.String transferSyntaxUID,
                                boolean tryMeta)
                         throws java.io.IOException

        Construct a stream to read DICOM data sets from the supplied stream.

        Parameters:
        i - the input stream to read from
        transferSyntaxUID - use this transfer syntax (may be null)
        tryMeta - if true, try to find a meta information header
        Throws:
        java.io.IOException - if an I/O error occurs
      • DicomInputStream

        public DicomInputStream​(java.io.File file,
                                java.lang.String transferSyntaxUID,
                                boolean tryMeta)
                         throws java.io.IOException

        Construct a stream to read DICOM data sets from the supplied stream.

        Parameters:
        file - the file to read from
        transferSyntaxUID - use this transfer syntax (may be null)
        tryMeta - if true, try to find a meta information header
        Throws:
        java.io.IOException - if an I/O error occurs
    • Method Detail

      • guessTransferSyntaxToReadDataSet

        public void guessTransferSyntaxToReadDataSet()
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • setTransferSyntaxToReadDataSet

        public void setTransferSyntaxToReadDataSet​(TransferSyntax ts)

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

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

        public void setReadingDataSet()

        Switch to the transfer syntax for reading the dataset.

      • areReadingDataSet

        public boolean areReadingDataSet()

        Are we reading the dataset?

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

        public void setReadingMetaHeader()

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

      • areReadingMetaHeader

        public boolean areReadingMetaHeader()

        Are we reading the meta information header?

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

        public boolean haveMetaHeader()

        Do we have 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
      • getTransferSyntaxToReadDataSet

        public TransferSyntax getTransferSyntaxToReadDataSet()

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

        Returns:
        the transfer syntax
      • getTransferSyntaxToReadMetaHeader

        public TransferSyntax getTransferSyntaxToReadMetaHeader()

        Get the transfer syntax to be used for reading 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)