Class 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:
    FileRaw
    • Field Detail

      • bufferBitSet

        private java.util.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 java.util.zip.DeflaterOutputStream deflaterStream
        DOCUMENT ME!
      • inflaterStream

        private java.util.zip.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 Detail

      • FileRawChunk

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

        public FileRawChunk​(java.lang.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 Detail

      • close

        public final void close()
                         throws java.io.IOException
        Closes the file.
        Throws:
        java.io.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 java.util.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 java.io.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:
        java.io.IOException - if there is an error reading the file
      • setImageFile

        public void setImageFile​(java.io.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 java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferDouble

        public void writeBufferDouble​(double[] buffer,
                                      int start,
                                      int end,
                                      boolean endianess)
                               throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferFloat

        public void writeBufferFloat​(float[] buffer,
                                     int start,
                                     int end,
                                     boolean endianess)
                              throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferInt

        public void writeBufferInt​(int[] buffer,
                                   int start,
                                   int end,
                                   boolean endianess)
                            throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferLong

        public void writeBufferLong​(long[] buffer,
                                    int start,
                                    int end,
                                    boolean endianess)
                             throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferRGB

        public void writeBufferRGB​(int[] buffer,
                                   int start,
                                   int end)
                            throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferRGB_USHORT

        public void writeBufferRGB_USHORT​(int[] buffer,
                                          int start,
                                          int end,
                                          boolean endianess)
                                   throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferShort

        public void writeBufferShort​(short[] buffer,
                                     int start,
                                     int end,
                                     boolean endianess)
                              throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferUByte

        public void writeBufferUByte​(short[] buffer,
                                     int start,
                                     int end)
                              throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferUInt

        public void writeBufferUInt​(long[] buffer,
                                    int start,
                                    int end,
                                    boolean endianess)
                             throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeBufferUShort

        public void writeBufferUShort​(int[] buffer,
                                      int start,
                                      int end,
                                      boolean endianess)
                               throws java.io.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:
        java.io.IOException - DOCUMENT ME!
      • writeImage

        public void writeImage​(ModelImage image,
                               int start,
                               int end)
                        throws java.io.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:
        java.io.IOException - DOCUMENT ME!