Class FileRawChunk

java.lang.Object
gov.nih.mipav.model.file.FileBase
gov.nih.mipav.model.file.FileRawChunk

public class FileRawChunk extends FileBase
The class reads and writes raw files of all data types: boolean, byte, short, int, long, float, and double. For the read process an offset can be passed as a parameter to identify the location in the file where the data starts. A number of file formats while not "raw" have data at a specific location after a fixed length but unknown header and therefore can be treated as raw.
Version:
0.1 Sept 2, 1997
Author:
Matthew J. McAuliffe, Ph.D.
See Also:
  • Field Details

    • RGB

      public static final int RGB
      DOCUMENT ME!
      See Also:
    • RRRGGGBBB

      public static final int RRRGGGBBB
      DOCUMENT ME!
      See Also:
    • bufferBitSet

      private BitSet bufferBitSet
      DOCUMENT ME!
    • bufferByte

      private byte[] bufferByte
      DOCUMENT ME!
    • bufferDouble

      private double[] bufferDouble
      DOCUMENT ME!
    • bufferFloat

      private float[] bufferFloat
      DOCUMENT ME!
    • bufferInt

      private int[] bufferInt
      DOCUMENT ME!
    • bufferLong

      private long[] bufferLong
      DOCUMENT ME!
    • bufferShort

      private short[] bufferShort
      DOCUMENT ME!
    • bufferSize

      private int bufferSize
      DOCUMENT ME!
    • compressionType

      private int compressionType
      DOCUMENT ME!
    • deflaterStream

      private DeflaterOutputStream deflaterStream
      DOCUMENT ME!
    • fileInfo

      private FileInfoBase fileInfo
      DOCUMENT ME!
    • inflaterStream

      private InflaterInputStream inflaterStream
      DOCUMENT ME!
    • numChannels

      private int numChannels
    • planarConfig

      private int planarConfig
      DOCUMENT ME!
    • RGBAOrder

      private boolean RGBAOrder
    • type

      private int type
      DOCUMENT ME!
    • minimumBitsMinus1

      private int minimumBitsMinus1
      Used in reading and writing boolean
    • shiftToDivide

      private int shiftToDivide
      Used in reading and writing boolean
    • threeByteInteger

      private boolean threeByteInteger
    • bitsAllocated

      private int bitsAllocated
    • bitsStored

      private int bitsStored
    • highBit

      private int highBit
  • Constructor Details

    • FileRawChunk

      public FileRawChunk(RandomAccessFile file, FileInfoBase fInfo)
      Raw reader/writer constructor.
      Parameters:
      file - random access file pointer
      fInfo - information that describes the image
    • FileRawChunk

      public FileRawChunk(String fileName, FileInfoBase fInfo, int rwFlag, int compress)
      Compressed raw reader/writer constructor.
      Parameters:
      fileName - the name of the file to read/write
      fInfo - information that describes the image
      rwFlag - whether we are reading or writing the file (READ or WRITE)
      compress - the compression method to use (should not be none)
  • Method Details

    • close

      public final void close() throws IOException
      Closes the file.
      Throws:
      IOException - DOCUMENT ME!
    • finalize

      public void finalize()
      Prepares this class for cleanup.
      Overrides:
      finalize in class FileBase
    • setMinimumBitsMinus1

      public void setMinimumBitsMinus1(int minimumBitsMinus1)
      Used in reading and writing boolean
      Parameters:
      minimumBitsMinus1 -
    • setThreeByteInteger

      public void setThreeByteInteger(boolean threeByteInteger)
    • setBitsAllocated

      public void setBitsAllocated(int bitsAllocated)
    • setBitsStored

      public void setBitsStored(int bitsStored)
    • setHighBit

      public void setHighBit(int highBit)
    • setShiftToDivide

      public void setShiftToDivide(int shiftToDivide)
      Used in reading and writing boolean
      Parameters:
      shiftToDivide -
    • getBitSetBuffer

      public BitSet getBitSetBuffer()
      Gets the Bitset buffer (binary image).
      Returns:
      the buffer
    • getByteBuffer

      public byte[] getByteBuffer()
      Gets the byte buffer (image).
      Returns:
      the buffer
    • getDoubleBuffer

      public double[] getDoubleBuffer()
      Gets the double buffer (image).
      Returns:
      the buffer
    • getFloatBuffer

      public float[] getFloatBuffer()
      Gets the float buffer (image).
      Returns:
      the buffer
    • getIntBuffer

      public int[] getIntBuffer()
      gGets the integer buffer (image).
      Returns:
      the buffer
    • getLongBuffer

      public long[] getLongBuffer()
      Gets the long buffer (image).
      Returns:
      the buffer
    • getShortBuffer

      public short[] getShortBuffer()
      Gets the short buffer (image).
      Returns:
      the buffer
    • readImage

      public void readImage(int type, long start, int length) throws IOException
      This method reads a raw chunk from a file.
      Parameters:
      type - type of data that is to be read
      start - points to where the data of the image is located.
      length - number of pixels to be read
      Throws:
      IOException - if there is an error reading the file
    • setImageFile

      public void setImageFile(RandomAccessFile file, FileInfoBase fInfo)
      Sets the classes file handle to the past in the method.
      Parameters:
      file - random access file pointer
      fInfo - information that describes the image
    • setNumChannels

      public void setNumChannels(int numChannels)
      Sets the number of channels used in RGB files.
      Parameters:
      numChannels - DOCUMENT ME!
    • setPlanarConfig

      public void setPlanarConfig(int _planarConfig)
      Sets the planar configuration for RGB images.
      Parameters:
      _planarConfig - 0 indicates pixels are RGB, RGB chunky 1 indicates pixels are RRR, GGG, BBB planar
    • setRGBAOrder

      public void setRGBAOrder(boolean RGBAOrder)
      DOCUMENT ME!
      Parameters:
      RGBAOrder - DOCUMENT ME!
    • writeBufferByte

      public void writeBufferByte(byte[] buffer, int start, int end) throws IOException
      This method writes a raw byte buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferDouble

      public void writeBufferDouble(double[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a double buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferFloat

      public void writeBufferFloat(float[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a float buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferInt

      public void writeBufferInt(int[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a int buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferLong

      public void writeBufferLong(long[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a int buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferRGB

      public void writeBufferRGB(int[] buffer, int start, int end) throws IOException
      This method writes a RGB buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferRGB_USHORT

      public void writeBufferRGB_USHORT(int[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a RGB_USHORT buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferShort

      public void writeBufferShort(short[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a raw short buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferUByte

      public void writeBufferUByte(short[] buffer, int start, int end) throws IOException
      This method writes a raw unsigned byte buffer to a file.
      Parameters:
      buffer - image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferUInt

      public void writeBufferUInt(long[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes an unisgned int buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeBufferUShort

      public void writeBufferUShort(int[] buffer, int start, int end, boolean endianess) throws IOException
      This method writes a raw unsigned short buffer to a file.
      Parameters:
      buffer - the image data buffer
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      endianess - the endianess of the data
      Throws:
      IOException - DOCUMENT ME!
    • writeImage

      public void writeImage(ModelImage image, int start, int end) throws IOException
      This method writes a raw image file (1D-5D).
      Parameters:
      image - image model from which the data will be read.
      start - start of data in the read image file in units of extents[0]*extents[1]
      end - end of data in the read image file in units of extents[0]*extents[1]
      Throws:
      IOException - DOCUMENT ME!