Class FileDicomBase

java.lang.Object
gov.nih.mipav.model.file.FileDicomBase
Direct Known Subclasses:
FileDicom

public class FileDicomBase extends Object
FileDICOMBase is an class that supports the reading/writing of DICOM files. It reads in a buffer of tags that can be parsed more quickly than continued random accesses to the harddrive.
Version:
1.0 June 30, 2005
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    private int
    Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    static final boolean
    Byte order.
    private int
    Buffer pointer (aka file pointer).
    static final long
    The size of the buffer that contains the tags of the DICOM image.
    protected final byte[]
    One byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.
    protected final byte[]
    Two byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.
    protected final byte[]
    Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write.
    protected final byte[]
    Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.
    protected long
    Total length of the image file.
    protected int
     
    protected int
     
    protected int
     
    protected int
     
    protected boolean
     
    static final boolean
    Byte order.
    protected boolean
    If file is a DICOMDIR this is false *
    protected int
    The number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc.
    protected boolean
    Flag indicating if the progress bar should be shown.
    Progress bar to show when reading in image file.
    Pointer to file to read or write from.
    static final int
    Read only access.
    static final int
    Read-write access.
    protected boolean
     
    protected byte[]
    The buffer that holds the tags of the DICOM image.
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Empty constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Prepares this class for cleanup.
    final int
    Reads unsigned bytes from file.
    final double
    getDouble(boolean endianess)
    Reads eight unsigned bytes from file.
    protected final long
     
    protected final int
    Gets the file/buffer pointer and returns it.
    final float
    getFloat(boolean endianess)
    Reads four unsigned bytes from file.
    final int
    getInt(boolean endianess)
    Reads four signed bytes from file.
    final long
    getLong(boolean endianess)
    Reads eight unsigned bytes from file.
    final int
    Reads signed bytes from file.
    final int
    getSignedShort(boolean endianess)
    Reads two byte signed short from file.
    final String
    getString(int length)
    Reads a string from a file of given length.
    final String
    getStringFromFile(int length)
    Reads a string from a file of given length.
    final long
    getUInt(boolean endianess)
    Reads four unsigned bytes from file.
    final int
    getUnsignedShort(boolean endianess)
    Reads two unsigned bytes from file.
    void
    Setups the allocation of memory for the byte buffer to load the entire image.
    boolean
    Returns whether this Dicom read is only interested in the header tags and not the image data (if it exists).
    boolean
    Returns flag that indicates that the progressBar is visible.
    void
    loadTagBuffer(int b3)
    Setups the allocation of memory for the byte buffer to load tags.
    int
    locateImageTag(int offset, int imageNumber, int b3)
    Locates a DICOM image beginning at the given offset.
    protected final void
    read(byte[] byteBuffer)
    Reads into the supplied buffer data from the DICOM tag buffer.
    private boolean
    searchForImageTag(byte[] tempTagBuffer, byte[] endianBuffer, int bufferIndex)
    Performs internal search for the image tag in a dicom file, given an appropriate endianess.
    protected final void
    seek(int value)
    Seeks to a point in the buffer.
    final void
    setBufferFloat(byte[] buffer, float data, int i, boolean endianess)
    Sets byte buffer with int.
    final void
    setBufferInt(byte[] buffer, int data, int i, boolean endianess)
    Sets byte buffer with int.
    final void
    setBufferLong(byte[] buffer, long data, int i, boolean endianess)
    Sets byte buffer with long.
    final void
    setBufferShort(byte[] buffer, short data, int i, boolean endianess)
    Sets byte buffer with int.
    final void
    setBufferString(byte[] buffer, String str, int i)
    Sets byte buffer with int.
    void
    setHeaderOnlyRead(boolean isHeaderOnly)
    Sets whether this Dicom read is only interested in the header tags and not the image data (if it exists).
    void
    setProgressBarVisible(boolean flag)
    Sets whether or not the progress bar should be visible.
    final void
    setTagBuffer(byte[] buffer)
    DOCUMENT ME!
    protected final void
    skipBytes(int value)
    Skips to a new point in the buffer.
    final void
    writeByte(byte data)
    Writes a byte to a file.
    final void
    writeDouble(double data, boolean endianess)
    Writes a double as eight bytes to a file.
    final void
    writeFloat(float data, boolean endianess)
    Writes a float as four bytes to a file.
    final void
    writeInt(int data, boolean endianess)
    Writes an int as four bytes to a file.
    final void
    writeLong(long data, boolean endianess)
    Writes a long as eight bytes to a file.
    final void
    writeShort(short data, boolean endianess)
    Writes a short as two bytes to a file.
    final void
    writeUnsignedShort(short data, boolean endianess)
    Writes an unsigned short as two bytes to a file.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LITTLE_ENDIAN

      public static final boolean LITTLE_ENDIAN
      Byte order. Rightmost byte is most significant.
      See Also:
    • BIG_ENDIAN

      public static final boolean BIG_ENDIAN
      Byte order. Leftmost byte is most significant.
      See Also:
    • READ

      public static final int READ
      Read only access.
      See Also:
    • READ_WRITE

      public static final int READ_WRITE
      Read-write access.
      See Also:
    • BUFFER_SIZE

      public static final long BUFFER_SIZE
      The size of the buffer that contains the tags of the DICOM image. Default = 400Thousand.
      See Also:
    • byteBuffer

      protected final byte[] byteBuffer
      One byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.
    • byteBuffer2

      protected final byte[] byteBuffer2
      Two byte array used to read/write in data so that one doesn't't need to be allocated with each read/write.
    • byteBuffer4

      protected final byte[] byteBuffer4
      Four byte array used to read/write in data so that one doesn't need to be allocated with each read/write.
    • byteBuffer8

      protected final byte[] byteBuffer8
      Eight byte array used to read/write in data so that they don't need to be allocated with each read/write.
    • fLength

      protected long fLength
      Total length of the image file.
    • pBarVisible

      protected boolean pBarVisible
      Flag indicating if the progress bar should be shown.
    • progressBar

      protected ProgressBarInterface progressBar
      Progress bar to show when reading in image file.
    • raFile

      protected RandomAccessFile raFile
      Pointer to file to read or write from.
    • tagBuffer

      protected byte[] tagBuffer
      The buffer that holds the tags of the DICOM image.
    • b1

      private int b1
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b2

      private int b2
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b3

      private int b3
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b4

      private int b4
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b5

      private int b5
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b6

      private int b6
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b7

      private int b7
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • b8

      private int b8
      Integer variable used to read/write in data so that they don't need to be allocated with each read/write.
    • bPtr

      private int bPtr
      Buffer pointer (aka file pointer).
    • notDir

      protected boolean notDir
      If file is a DICOMDIR this is false *
    • numEmbeddedImages

      protected int numEmbeddedImages
      The number of images inside of this file which are not the main displayable image (may be icon, RT planning, etc.
    • isDicomRecv

      protected boolean isDicomRecv
    • imageGroupWord

      protected int imageGroupWord
    • imageElementWord

      protected int imageElementWord
    • imageElementLength

      protected int imageElementLength
    • imageTagLocation

      protected int imageTagLocation
    • TAMAR

      protected boolean TAMAR
    • SPECTROSCOPY

      protected boolean SPECTROSCOPY
  • Constructor Details

    • FileDicomBase

      public FileDicomBase()
      Empty constructor.
  • Method Details

    • finalize

      public void finalize()
      Prepares this class for cleanup.
      Overrides:
      finalize in class Object
    • getByte

      public final int getByte() throws IOException
      Reads unsigned bytes from file.
      Returns:
      The value of unsigned byte read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • getSignedByte

      public final int getSignedByte() throws IOException
      Reads signed bytes from file.
      Returns:
      The value of signed byte read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • getDouble

      public final double getDouble(boolean endianess) throws IOException
      Reads eight unsigned bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the double read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getFloat

      public final float getFloat(boolean endianess) throws IOException
      Reads four unsigned bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the float read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getInt

      public final int getInt(boolean endianess) throws IOException
      Reads four signed bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the integer read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getLong

      public final long getLong(boolean endianess) throws IOException
      Reads eight unsigned bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the long read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getSignedShort

      public final int getSignedShort(boolean endianess) throws IOException
      Reads two byte signed short from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of signed short read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • getString

      public final String getString(int length) throws IOException
      Reads a string from a file of given length.
      Parameters:
      length - Number of bytes that form the string.
      Returns:
      The string read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getStringFromFile

      public final String getStringFromFile(int length) throws IOException
      Reads a string from a file of given length.
      Parameters:
      length - Number of bytes that form the string.
      Returns:
      The string read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getUInt

      public final long getUInt(boolean endianess) throws IOException
      Reads four unsigned bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of the integer read from the file.
      Throws:
      IOException - if there is an error reading the file
    • getUnsignedShort

      public final int getUnsignedShort(boolean endianess) throws IOException
      Reads two unsigned bytes from file.
      Parameters:
      endianess - true indicates big endian byte order, false indicates little endian.
      Returns:
      The value of unsigned short read from the file returned as an int.
      Throws:
      IOException - if there is an error reading the file
    • initializeFullRead

      public void initializeFullRead()
      Setups the allocation of memory for the byte buffer to load the entire image.
    • isProgressBarVisible

      public boolean isProgressBarVisible()
      Returns flag that indicates that the progressBar is visible.
      Returns:
      true if progress bar is visible, false if not visible.
    • searchForImageTag

      private boolean searchForImageTag(byte[] tempTagBuffer, byte[] endianBuffer, int bufferIndex)
      Performs internal search for the image tag in a dicom file, given an appropriate endianess.
    • loadTagBuffer

      public void loadTagBuffer(int b3) throws IOException
      Setups the allocation of memory for the byte buffer to load tags. This tag buffer is a cache to speed the loading of the images.
      Throws:
      IOException
    • locateImageTag

      public int locateImageTag(int offset, int imageNumber, int b3)
      Locates a DICOM image beginning at the given offset. When multiple images after the offset exist, imageNumber can be used to specify the exact image to retrieve.
    • setBufferFloat

      public final void setBufferFloat(byte[] buffer, float data, int i, boolean endianess)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Float data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      endianess - true indicates big endian byte order, false indicates little endian.
    • setBufferInt

      public final void setBufferInt(byte[] buffer, int data, int i, boolean endianess)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Integer data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      endianess - true indicates big endian byte order, false indicates little endian.
    • setBufferLong

      public final void setBufferLong(byte[] buffer, long data, int i, boolean endianess)
      Sets byte buffer with long.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Long data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      endianess - true indicates big endian byte order, false indicates little endian.
    • setBufferShort

      public final void setBufferShort(byte[] buffer, short data, int i, boolean endianess)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      data - Short data is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
      endianess - true indicates big endian byte order, false indicates little endian.
    • setBufferString

      public final void setBufferString(byte[] buffer, String str, int i)
      Sets byte buffer with int.
      Parameters:
      buffer - Byte buffers where data is to be stored.
      str - String containing integer data which is broken down in bytes and stored in the byte buffer.
      i - Index into byte buffer.
    • setProgressBarVisible

      public void setProgressBarVisible(boolean flag)
      Sets whether or not the progress bar should be visible.
      Parameters:
      flag - true if should be visible, false if not visible.
    • setTagBuffer

      public final void setTagBuffer(byte[] buffer)
      DOCUMENT ME!
      Parameters:
      buffer - byte[]
    • writeDouble

      public final void writeDouble(double data, boolean endianess) throws IOException
      Writes a double as eight bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeFloat

      public final void writeFloat(float data, boolean endianess) throws IOException
      Writes a float as four bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeInt

      public final void writeInt(int data, boolean endianess) throws IOException
      Writes an int as four bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeLong

      public final void writeLong(long data, boolean endianess) throws IOException
      Writes a long as eight bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeShort

      public final void writeShort(short data, boolean endianess) throws IOException
      Writes a short as two bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeUnsignedShort

      public final void writeUnsignedShort(short data, boolean endianess) throws IOException
      Writes an unsigned short as two bytes to a file.
      Parameters:
      data - Data to be written to file.
      endianess - true indicates big endian byte order, false indicates little endian.
      Throws:
      IOException - if there is an error writing the file
    • writeByte

      public final void writeByte(byte data) throws IOException
      Writes a byte to a file.
      Parameters:
      data - Data to be written to file.
      Throws:
      IOException - if there is an error writing the file
    • getFilePointer

      protected final int getFilePointer()
      Gets the file/buffer pointer and returns it.
      Returns:
      the file/buffer pointer
    • getFileLength

      protected final long getFileLength()
    • read

      protected final void read(byte[] byteBuffer)
      Reads into the supplied buffer data from the DICOM tag buffer.
      Parameters:
      byteBuffer - byte[]
    • seek

      protected final void seek(int value)
      Seeks to a point in the buffer.
      Parameters:
      value - indicates the new buffer pointer value
    • skipBytes

      protected final void skipBytes(int value)
      Skips to a new point in the buffer.
      Parameters:
      value - number of bytes to skip
    • isHeaderOnlyRead

      public boolean isHeaderOnlyRead()
      Returns whether this Dicom read is only interested in the header tags and not the image data (if it exists). Used by dcm recv and in cases like spectroscopy where there isn't a true image, but some tags may contain data that triggers the image search parameters ("7F" hex value, etc.).
      Returns:
      Whether the image data should be searched for or otherwise read.
    • setHeaderOnlyRead

      public void setHeaderOnlyRead(boolean isHeaderOnly)
      Sets whether this Dicom read is only interested in the header tags and not the image data (if it exists). Used by dcm recv and in cases like spectroscopy where there isn't a true image, but some tags may contain data that triggers the image search parameters ("7F" hex value, etc.).
      Parameters:
      isHeaderOnly - Whether we are only interested in reading the tags from the header, not the image data.