Class ByteReader


  • public class ByteReader
    extends Object
    Read through a byte array
    Author:
    osbornb
    • Constructor Detail

      • ByteReader

        public ByteReader​(byte[] bytes)
        Constructor
        Parameters:
        bytes - bytes
      • ByteReader

        public ByteReader​(byte[] bytes,
                          ByteOrder byteOrder)
        Constructor
        Parameters:
        bytes - bytes
        byteOrder - byte order
    • Method Detail

      • getNextByte

        public int getNextByte()
        Get the next byte to be read
        Returns:
        next byte to be read
      • setNextByte

        public void setNextByte​(long nextByte)
        Set the next byte to be read
        Parameters:
        nextByte - next byte
      • getByteOrder

        public ByteOrder getByteOrder()
        Get the byte order
        Returns:
        byte order
      • setByteOrder

        public void setByteOrder​(ByteOrder byteOrder)
        Set the byte order
        Parameters:
        byteOrder - byte order
      • hasByte

        public boolean hasByte()
        Check if there is at least one more byte left to read
        Returns:
        true more bytes left to read
      • hasByte

        public boolean hasByte​(int offset)
        Check if there is at least one more byte left to read
        Parameters:
        offset - byte offset
        Returns:
        true more bytes left to read
      • hasBytes

        public boolean hasBytes​(int count)
        Check if there are the provided number of bytes left to read
        Parameters:
        count - number of bytes
        Returns:
        true if has at least the number of bytes left
      • hasBytes

        public boolean hasBytes​(int offset,
                                int count)
        Check if there are the provided number of bytes left to read
        Parameters:
        offset - byte offset
        count - number of bytes
        Returns:
        true if has at least the number of bytes left
      • readByte

        public byte readByte()
        Read a byte
        Returns:
        byte
      • readByte

        public byte readByte​(int offset)
        Read a byte
        Parameters:
        offset - byte offset
        Returns:
        byte
      • readUnsignedByte

        public short readUnsignedByte()
        Read an unsigned byte
        Returns:
        unsigned byte as short
      • readUnsignedByte

        public short readUnsignedByte​(int offset)
        Read an unsigned byte
        Parameters:
        offset - byte offset
        Returns:
        unsigned byte as short
      • readBytes

        public byte[] readBytes​(int num)
        Read a number of bytes
        Parameters:
        num - number of bytes
        Returns:
        bytes
      • readBytes

        public byte[] readBytes​(int offset,
                                int num)
        Read a number of bytes
        Parameters:
        offset - byte offset
        num - number of bytes
        Returns:
        bytes
      • readShort

        public short readShort()
        Read a short
        Returns:
        short
      • readShort

        public short readShort​(int offset)
        Read a short
        Parameters:
        offset - byte offset
        Returns:
        short
      • readUnsignedShort

        public int readUnsignedShort()
        Read an unsigned short
        Returns:
        unsigned short as int
      • readUnsignedShort

        public int readUnsignedShort​(int offset)
        Read an unsigned short
        Parameters:
        offset - byte offset
        Returns:
        unsigned short as int
      • readInt

        public int readInt()
        Read an integer
        Returns:
        integer
      • readInt

        public int readInt​(int offset)
        Read an integer
        Parameters:
        offset - byte offset
        Returns:
        integer
      • readUnsignedInt

        public long readUnsignedInt()
        Read an unsigned int
        Returns:
        unsigned int as long
      • readUnsignedInt

        public long readUnsignedInt​(int offset)
        Read an unsigned int
        Parameters:
        offset - byte offset
        Returns:
        unsigned int as long
      • readFloat

        public float readFloat()
        Read a float
        Returns:
        float
      • readFloat

        public float readFloat​(int offset)
        Read a float
        Parameters:
        offset - byte offset
        Returns:
        float
      • readDouble

        public double readDouble()
        Read a double
        Returns:
        double
      • readDouble

        public double readDouble​(int offset)
        Read a double
        Parameters:
        offset - byte offset
        Returns:
        double
      • byteLength

        public int byteLength()
        Get the byte length
        Returns:
        byte length