Package com.tonic.parser
Class AbstractParser
- java.lang.Object
-
- com.tonic.parser.AbstractParser
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]getBytes()Gets the classes origonal bytesintgetIndex()intgetLength()Gets the byte array length.bytereadByte()Reads a signed byte.voidreadBytes(byte[] code, int start, int length)Reads multiple bytes into destination array.doublereadDouble()Reads a double value.floatreadFloat()Reads a float value.intreadInt()Reads a signed int in big-endian order.longreadLong()Reads a signed long in big-endian order.shortreadShort()Reads a signed short in big-endian order.intreadUnsignedByte()Reads an unsigned byte (0 to 255).longreadUnsignedInt()Reads an unsigned int (0 to 4,294,967,295) in big-endian order.BigIntegerreadUnsignedLong()Reads an unsigned long in big-endian order.intreadUnsignedShort()Reads an unsigned short (0 to 65,535) in big-endian order.StringreadUtf8()Reads a UTF-8 encoded string.voidrebuild()Rebuilds byte array from current state.
-
-
-
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
-
rebuild
public final void rebuild() throws IOExceptionRebuilds byte array from current state.- Throws:
IOException- if writing failsIncorrectFormatException- if rebuilt array fails verification
-
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
-
readUtf8
public final String readUtf8()
Reads a UTF-8 encoded string.- Returns:
- UTF-8 string
- 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 arraystart- starting position in destinationlength- number of bytes to read- Throws:
IndexOutOfBoundsException- if insufficient bytes
-
-