public class ByteArray
extends java.lang.Object
Various static methods helpful for manipulating arrays of bytes and extracting values from them.
Modifier and Type | Method and Description |
---|---|
static int |
bigEndianToUnsignedInt(byte[] b)
Extract an unsigned big endian integer from an entire byte array.
|
static int |
bigEndianToUnsignedInt(byte[] b,
int offset,
int length)
Extract an unsigned big endian integer from a byte array.
|
static byte[] |
concatenate(byte[] src1,
byte[] src2)
Concatenate the entire contents of two byte arrays into a new byte array.
|
static byte[] |
concatenate(byte[] src1,
int offset1,
int length1,
byte[] src2,
int offset2,
int length2)
Concatenate portions of two byte arrays into a new byte array.
|
static byte[] |
extractBytes(byte[] src,
int offset,
int length)
Extract a portion of a byte array into a new byte array.
|
static byte[] |
intToBigEndianArray(int value,
int length)
Extract an integer into a big endian byte array.
|
static byte[] |
intToLittleEndianArray(int value,
int length)
Extract an integer into a little endian byte array.
|
static void |
main(java.lang.String[] arg)
Testing.
|
static byte[] |
readFully(java.lang.String filename) |
static void |
swapEndianness(byte[] src,
int byteCount,
int wordLength)
Swap the byte order (endianness) of fixed length words within a byte array.
|
public static final int bigEndianToUnsignedInt(byte[] b)
Extract an unsigned big endian integer from an entire byte array.
b
- the byte array which is the big endian encoded integerpublic static final int bigEndianToUnsignedInt(byte[] b, int offset, int length)
Extract an unsigned big endian integer from a byte array.
b
- the byte array containing the big endian encoded integeroffset
- the offset of the start of the integer in the byte arraylength
- the number of bytes that the integer occupies in the byte arraypublic static final byte[] concatenate(byte[] src1, byte[] src2)
Concatenate the entire contents of two byte arrays into a new byte array.
src1
- the first byte arraysrc2
- the second byte arraypublic static final byte[] concatenate(byte[] src1, int offset1, int length1, byte[] src2, int offset2, int length2)
Concatenate portions of two byte arrays into a new byte array.
src1
- the first byte arrayoffset1
- the offset of the bytes to be extracted from the first byte arraylength1
- the number of bytes to be extracted from the first byte arraysrc2
- the second byte arrayoffset2
- the offset of the bytes to be extracted from the second byte arraylength2
- the number of bytes to be extracted from the second byte arraypublic static final byte[] extractBytes(byte[] src, int offset, int length)
Extract a portion of a byte array into a new byte array.
src
- the source byte arrayoffset
- the offset of the bytes to be extractedlength
- the number of bytes to be extractedpublic static final byte[] intToBigEndianArray(int value, int length)
Extract an integer into a big endian byte array.
value
- the integer valuelength
- the length of the byte arraypublic static final byte[] intToLittleEndianArray(int value, int length)
Extract an integer into a little endian byte array.
value
- the integer valuelength
- the length of the byte arraypublic static void main(java.lang.String[] arg)
Testing.
arg
- ignoredpublic static final byte[] readFully(java.lang.String filename) throws java.io.IOException
java.io.IOException
public static final void swapEndianness(byte[] src, int byteCount, int wordLength)
Swap the byte order (endianness) of fixed length words within a byte array.
src
- the byte array (swapped in place)byteCount
- the number of bytes in the array to swapwordLength
- the length in bytes of each word