Package com.pnfsoftware.jeb.util.io
Class ByteArray
java.lang.Object
com.pnfsoftware.jeb.util.io.ByteArray
Primitive reader for little-endian byte arrays. Support for fixed-length primitive and
variable-length LEB128-encoded primitives.
A max bound (see maxPosition()) can be set on the array. It can be adjusted at any
time after object creation. When a max bound is set, reading past that bound will generate a
runtime exception. The bound is always relative to the full array length.
-
Constructor Summary
ConstructorsConstructorDescriptionByteArray(byte[] bytes) Create a little-endianbyte[]reader with an initial index of 0.ByteArray(byte[] bytes, int pos) Create a little-endianbyte[]reader with the provided initial index.ByteArray(byte[] bytes, int pos, int maxpos) Create a little-endianbyte[]reader with the provided initial and maximum positions. -
Method Summary
Modifier and TypeMethodDescriptionintbyte[]bytes()byteget()Read one byte.byte[]get(int cnt) Read bytes from the current position.inti16()Read a signed little-endian 16-bit integer.inti32()Read a signed little-endian 32-bit integer.longi64()Read a signed little-endian 64-bit integer.inti8()Read a signed 8-bit integer.intGet the current maximum readable position.intmaxPosition(int maxpos) intposition()Get the current read position.intposition(int pos) voidskip(int cnt) Advance or rewind the current position.sub(int len) Create a view of this object.toString()intu16()Read an unsigned little-endian 16-bit integer.intu31()Read a non-negative little-endian 32-bit integer.longu32()Read an unsigned little-endian 32-bit integer.longu63()Read a non-negative little-endian 64-bit integer.intu8()Read an unsigned 8-bit integer.intvari32()Read a signed LEB128-encoded 32-bit integer.longvari64()Read a signed LEB128-encoded 64-bit integer.intvaru16()Read an unsigned LEB128-encoded 16-bit integer.longvaru32()Read an unsigned LEB128-encoded 32-bit integer.
-
Constructor Details
-
ByteArray
public ByteArray(byte[] bytes) Create a little-endianbyte[]reader with an initial index of 0.- Parameters:
bytes- backing byte array
-
ByteArray
public ByteArray(byte[] bytes, int pos) Create a little-endianbyte[]reader with the provided initial index.- Parameters:
bytes- backing byte arraypos- initial index
-
ByteArray
public ByteArray(byte[] bytes, int pos, int maxpos) Create a little-endianbyte[]reader with the provided initial and maximum positions.- Parameters:
bytes- backing byte arraypos- initial indexmaxpos- maximum index
-
-
Method Details
-
sub
Create a view of this object.- Parameters:
len- count of bytes from the current position- Returns:
- a new byte array
-
bytes
public byte[] bytes()- Returns:
- the underlying byte array provided to the constructor
-
maxPosition
public int maxPosition(int maxpos) - Parameters:
maxpos- the new max position (which cannot be less than the current position)- Returns:
- the previous max position
-
maxPosition
public int maxPosition()Get the current maximum readable position.- Returns:
- maximum position
-
position
public int position(int pos) - Parameters:
pos- the new position (which cannot be more than the current max position)- Returns:
- the previous position
-
position
public int position()Get the current read position.- Returns:
- current position
-
available
public int available()- Returns:
- the number of bytes available from the current position to the max position
-
skip
public void skip(int cnt) Advance or rewind the current position.- Parameters:
cnt- signed byte count to skip
-
get
public byte get()Read one byte.- Returns:
- byte at the current position
-
get
public byte[] get(int cnt) Read bytes from the current position.- Parameters:
cnt- number of bytes to read- Returns:
- newly allocated byte array
-
i8
public int i8()Read a signed 8-bit integer.- Returns:
- decoded value
-
u8
public int u8()Read an unsigned 8-bit integer.- Returns:
- decoded value
-
i16
public int i16()Read a signed little-endian 16-bit integer.- Returns:
- decoded value
-
u16
public int u16()Read an unsigned little-endian 16-bit integer.- Returns:
- decoded value
-
u31
public int u31()Read a non-negative little-endian 32-bit integer.- Returns:
- decoded value
-
i32
public int i32()Read a signed little-endian 32-bit integer.- Returns:
- decoded value
-
u32
public long u32()Read an unsigned little-endian 32-bit integer.- Returns:
- decoded value
-
u63
public long u63()Read a non-negative little-endian 64-bit integer.- Returns:
- decoded value
-
i64
public long i64()Read a signed little-endian 64-bit integer.- Returns:
- decoded value
-
varu16
public int varu16()Read an unsigned LEB128-encoded 16-bit integer.- Returns:
- decoded value
-
vari32
public int vari32()Read a signed LEB128-encoded 32-bit integer.- Returns:
- decoded value
-
varu32
public long varu32()Read an unsigned LEB128-encoded 32-bit integer.- Returns:
- decoded value
-
vari64
public long vari64()Read a signed LEB128-encoded 64-bit integer.- Returns:
- decoded value
-
toString
-