Class AbstractParser

  • Direct Known Subclasses:
    ClassFile

    public abstract class AbstractParser
    extends Object
    An abstract parser for reading various data types from a byte array.
    • Method Detail

      • getBytes

        public byte[] getBytes()
        Gets the classes origonal bytes
        Returns:
        class bytes
      • getIndex

        public int getIndex()
        Returns:
        the index
      • getLength

        public final int getLength()
        Gets the byte array length.
        Returns:
        length of the byte array
      • readByte

        public final byte readByte()
        Reads a signed byte.
        Returns:
        signed byte value
        Throws:
        IndexOutOfBoundsException - if out of bounds
      • readUnsignedByte

        public final int readUnsignedByte()
        Reads an unsigned byte (0 to 255).
        Returns:
        unsigned byte as int
        Throws:
        IndexOutOfBoundsException - if out of bounds
      • readShort

        public final short readShort()
        Reads a signed short in big-endian order.
        Returns:
        signed short value
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readUnsignedShort

        public final int readUnsignedShort()
        Reads an unsigned short (0 to 65,535) in big-endian order.
        Returns:
        unsigned short as int
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readInt

        public final int readInt()
        Reads a signed int in big-endian order.
        Returns:
        signed int value
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readUnsignedInt

        public final long readUnsignedInt()
        Reads an unsigned int (0 to 4,294,967,295) in big-endian order.
        Returns:
        unsigned int as long
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readLong

        public final long readLong()
        Reads a signed long in big-endian order.
        Returns:
        signed long value
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readUnsignedLong

        public final BigInteger readUnsignedLong()
        Reads an unsigned long in big-endian order.
        Returns:
        unsigned long as BigInteger
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readDouble

        public final double readDouble()
        Reads a double value.
        Returns:
        double value
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readFloat

        public final float readFloat()
        Reads a float value.
        Returns:
        float value
        Throws:
        IndexOutOfBoundsException - if insufficient bytes
      • readBytes

        public final void readBytes​(byte[] code,
                                    int start,
                                    int length)
        Reads multiple bytes into destination array.
        Parameters:
        code - destination array
        start - starting position in destination
        length - number of bytes to read
        Throws:
        IndexOutOfBoundsException - if insufficient bytes