Package ucar.nc2.iosp

Class BitReader


  • public class BitReader
    extends Object
    Helper for reading data that has been bit packed.
    • Constructor Detail

      • BitReader

        public BitReader​(byte[] test)
      • BitReader

        public BitReader​(RandomAccessFile raf,
                         long startPos)
                  throws IOException
        Constructor
        Parameters:
        raf - the RandomAccessFile
        startPos - points to start of data in data section, in bytes
        Throws:
        IOException - on seek error
    • Method Detail

      • incrByte

        public void incrByte()
        Go to the next byte in the stream
      • setBitOffset

        public void setBitOffset​(int bitOffset)
                          throws IOException
        Position file at bitOffset from startPos
        Parameters:
        bitOffset - bit offset from starting position
        Throws:
        IOException - on io error
      • getPos

        public long getPos()
        Get the current file offset in bytes.
      • bits2UInt

        public long bits2UInt​(int nb)
                       throws IOException
        Read the next nb bits and return the value as an unsigned long.
        Parameters:
        nb - the number of bits to convert to int, must be 0 < nb ≤ 64.
        Returns:
        the value as an unsigned long.
        Throws:
        IOException - on read error
      • bits2SInt

        public long bits2SInt​(int nb)
                       throws IOException
        Read the next nb bits and return the value as a signed long.
        Parameters:
        nb - the number of bits to convert to int, must be ≤ 64.
        Returns:
        the value as a signed long
        Throws:
        IOException - on read error