public class ByteArray extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BIG_ENDIAN
Access mode big endian.
|
static int |
BYTE_SIZE
The size of a byte.
|
static int |
CHAR_SIZE
The size of a char.
|
static int |
INT_SIZE
The size of an int.
|
static int |
LITTLE_ENDIAN
Access mode little endian.
|
static int |
LONG_SIZE
The size of a long.
|
static int |
SHORT_SIZE
The size of a short.
|
Constructor and Description |
---|
ByteArray() |
Modifier and Type | Method and Description |
---|---|
static void |
clear(byte[] array,
int offset,
int length)
Fills a zone of a byte array with
0 . |
static int |
getPlatformEndianness()
Gets whether the platform is in big endian or little endian.
|
static char |
readChar(byte[] array,
int offset)
Reads a char in the given byte array at the given offset respecting the
endianness of the platform.
|
static char |
readChar(byte[] array,
int offset,
int endianness)
Reads a char in the given byte array at the given offset respecting the
endianness of the array.
|
static int |
readInt(byte[] array,
int offset)
Reads an int in the given byte array at the given offset respecting the
endianness of the platform.
|
static int |
readInt(byte[] array,
int offset,
int endianness)
Reads an int in the given byte array at the given offset respecting the
endianness of the array.
|
static long |
readLong(byte[] array,
int offset)
Reads a long in the given byte array at the given offset respecting the
endianness of the platform.
|
static long |
readLong(byte[] array,
int offset,
int endianness)
Reads a long in the given byte array at the given offset respecting the
endianness of the array.
|
static short |
readShort(byte[] array,
int offset)
Reads a short in the given byte array at the given offset respecting the
endianness of the platform.
|
static short |
readShort(byte[] array,
int offset,
int endianness)
Reads a short in the given byte array at the given offset respecting the
endianness of the array.
|
static int |
readUnsignedByte(byte[] array,
int offset)
Reads an unsigned-byte in the given byte array at the given offset respecting
the endianness of the platform.
|
static void |
set(byte[] array,
byte value,
int offset,
int length)
Fills a zone of a byte array with the given value.
|
static void |
writeInt(byte[] array,
int offset,
int value)
Writes an int in the given byte array at the given offset respecting the
endianness of the platform.
|
static void |
writeInt(byte[] array,
int offset,
int value,
int endianness)
Writes an int in the given byte array at the given offset respecting the
endianness of the array.
|
static void |
writeLong(byte[] array,
int offset,
long value)
Writes a long in the given byte array at the given offset respecting the
endianness of the platform.
|
static void |
writeLong(byte[] array,
int offset,
long value,
int endianness)
Writes a long in the given byte array at the given offset respecting the
endianness of the array.
|
static void |
writeShort(byte[] array,
int offset,
int value)
Writes a short in the given byte array at the given offset respecting the
endianness of the platform.
|
static void |
writeShort(byte[] array,
int offset,
int value,
int endianness)
Writes a short in the given byte array at the given offset respecting the
endianness of the array.
|
public static final int BIG_ENDIAN
public static final int BYTE_SIZE
public static final int CHAR_SIZE
public static final int INT_SIZE
public static final int LITTLE_ENDIAN
public static final int LONG_SIZE
public static final int SHORT_SIZE
public static void clear(byte[] array, int offset, int length)
0
.array
- the byte array to clearoffset
- the offset of the zone to clearlength
- the length of the zone to clearArrayIndexOutOfBoundsException
- if write outside the bounds of the given arraypublic static int getPlatformEndianness()
BIG_ENDIAN
if the platform is in big endian,
LITTLE_ENDIAN
if in little endianpublic static char readChar(byte[] array, int offset)
array
- the byte array to read inoffset
- the offset of the value to readNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayCHAR_SIZE
public static char readChar(byte[] array, int offset, int endianness)
array
- the byte array to read inoffset
- the offset of the value to readendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)NullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayCHAR_SIZE
public static int readInt(byte[] array, int offset)
array
- the byte array to read inoffset
- the offset of the value to readNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayINT_SIZE
public static int readInt(byte[] array, int offset, int endianness)
array
- the byte array to read inoffset
- the offset of the value to readendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)NullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayINT_SIZE
public static long readLong(byte[] array, int offset)
array
- the byte array to read inoffset
- the offset of the value to readNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayLONG_SIZE
public static long readLong(byte[] array, int offset, int endianness)
array
- the byte array to read inoffset
- the offset of the value to readendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)NullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayLONG_SIZE
public static short readShort(byte[] array, int offset)
array
- the byte array to read inoffset
- the offset of the value to readNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arraySHORT_SIZE
public static short readShort(byte[] array, int offset, int endianness)
array
- the byte array to read inoffset
- the offset of the value to readendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)NullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arraySHORT_SIZE
public static int readUnsignedByte(byte[] array, int offset)
array
- the byte array to read inoffset
- the offset of the value to readNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if read outside the bounds of the given arrayBYTE_SIZE
public static void set(byte[] array, byte value, int offset, int length)
array
- the byte array to setvalue
- the value to fill the zone withoffset
- the offset of the zone to setlength
- the length of the zone to setArrayIndexOutOfBoundsException
- if write outside the bounds of the given arraypublic static void writeInt(byte[] array, int offset, int value)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeArrayIndexOutOfBoundsException
- if write outside the bounds of the given arrayINT_SIZE
public static void writeInt(byte[] array, int offset, int value, int endianness)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)ArrayIndexOutOfBoundsException
- if write outside the bounds of the given arrayINT_SIZE
public static void writeLong(byte[] array, int offset, long value)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeArrayIndexOutOfBoundsException
- if write outside the bounds of the given arrayLONG_SIZE
public static void writeLong(byte[] array, int offset, long value, int endianness)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)ArrayIndexOutOfBoundsException
- if write outside the bounds of the given arrayLONG_SIZE
public static void writeShort(byte[] array, int offset, int value)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeNullPointerException
- if the given array is nullArrayIndexOutOfBoundsException
- if write outside the bounds of the given arraySHORT_SIZE
public static void writeShort(byte[] array, int offset, int value, int endianness)
array
- the byte array to write inoffset
- the offset of the value to writevalue
- the value to writeendianness
- the access mode (BIG_ENDIAN
or LITTLE_ENDIAN
)ArrayIndexOutOfBoundsException
- if write outside the bounds of the given arraySHORT_SIZE