Class BitReader


  • public class BitReader
    extends Object
    A class is used to extract values across byte boundaries with arbitrary bit positions.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitReader​(byte[] array, int index)
      Initializes a new instance of the BitReader class with specified bytes buffer and start position in byte.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Assign the internal read buffer to null.
      boolean getCurrent()  
      boolean moveNext()
      Advances the enumerator to the next bit of the byte array.
      byte[] readBytes​(int readingLength)
      Reading the bytes specified by the byte length.
      UUID readGuid()
      Read as a GUID from the current offset position and increate the bit offset with 128 bit.
      short readInt16​(int readingLength)
      Read specified bit length content as an UInt16 type and increase the bit offset with the specified length.
      int readInt32​(int readingLength)
      Read specified bit length content as an Int32 type and increase the bit offset with the specified length.
      int readUInt16​(int readingLength)  
      int readUInt32​(int readingLength)
      Read specified bit length content as an UInt32 type and increase the bit offset with the specified length.
      long readUInt64​(int readingLength)
      Read specified bit length content as an UInt64 type and increase the bit offset.
      void reset()
      Sets the enumerator to its initial position, which is before the first bit in the byte array.
    • Constructor Detail

      • BitReader

        public BitReader​(byte[] array,
                         int index)
        Initializes a new instance of the BitReader class with specified bytes buffer and start position in byte.
        Parameters:
        array - Specify the byte array which contains the bytes need to be read.
        index - Specify the start position in byte.
    • Method Detail

      • getCurrent

        public boolean getCurrent()
      • readUInt64

        public long readUInt64​(int readingLength)
                        throws IOException
        Read specified bit length content as an UInt64 type and increase the bit offset.
        Parameters:
        readingLength - Specify the reading bit length.
        Returns:
        Return the UInt64 type value.
        Throws:
        IOException
      • readUInt32

        public int readUInt32​(int readingLength)
                       throws IOException
        Read specified bit length content as an UInt32 type and increase the bit offset with the specified length.
        Parameters:
        readingLength - Specify the reading bit length.
        Returns:
        Return the UInt32 type value.
        Throws:
        IOException
      • readBytes

        public byte[] readBytes​(int readingLength)
                         throws IOException
        Reading the bytes specified by the byte length.
        Parameters:
        readingLength - Specify the reading byte length.
        Returns:
        Return the read bytes array.
        Throws:
        IOException
      • readInt16

        public short readInt16​(int readingLength)
                        throws IOException
        Read specified bit length content as an UInt16 type and increase the bit offset with the specified length.
        Parameters:
        readingLength - Specify the reading bit length.
        Returns:
        Return the UInt16 value.
        Throws:
        IOException
      • readInt32

        public int readInt32​(int readingLength)
                      throws IOException
        Read specified bit length content as an Int32 type and increase the bit offset with the specified length.
        Parameters:
        readingLength - Specify the reading bit length.
        Returns:
        Return the Int32 type value.
        Throws:
        IOException
      • readGuid

        public UUID readGuid()
                      throws IOException
        Read as a GUID from the current offset position and increate the bit offset with 128 bit.
        Returns:
        Return the GUID value.
        Throws:
        IOException
      • moveNext

        public boolean moveNext()
        Advances the enumerator to the next bit of the byte array.
        Returns:
        true if the enumerator was successfully advanced to the next bit; false if the enumerator has passed the end of the byte array.
      • dispose

        public void dispose()
        Assign the internal read buffer to null.
      • reset

        public void reset()
        Sets the enumerator to its initial position, which is before the first bit in the byte array.