Package ucar.nc2.iosp

Class BitReader

java.lang.Object
ucar.nc2.iosp.BitReader

public class BitReader extends Object
Helper for reading data that has been bit packed.
Since:
Apr 7, 2008
  • Constructor Summary

    Constructors
    Constructor
    Description
    BitReader(byte[] test)
     
    BitReader(RandomAccessFile raf, long startPos)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    bits2SInt(int nb)
    Read the next nb bits and return an Signed Long .
    long
    bits2UInt(int nb)
    Read the next nb bits and return an Unsigned Long .
    static boolean
    getBit(long decimal, int N)
     
    long
     
    void
    Go to the next byte in the stream
    static long
    setBit(long decimal, int N, boolean value)
     
    void
    setBitOffset(int bitOffset)
    Position file at bitOffset from startPos

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 read error
  • Method Details

    • 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()
    • bits2UInt

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

      public long bits2SInt(int nb) throws IOException
      Read the next nb bits and return an Signed Long .
      Parameters:
      nb - the number of bits to convert to int, must be <= 64.
      Returns:
      result
      Throws:
      IOException - on read error
    • setBit

      public static long setBit(long decimal, int N, boolean value)
    • getBit

      public static boolean getBit(long decimal, int N)