public final class ByteArrayUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static boolean |
LITTLE_ENDIAN
Whether the machine is little endian
|
Modifier and Type | Method and Description |
---|---|
static void |
clear(byte[] array)
Sets all elements to 0
|
static int |
count(byte[] data,
byte value)
Returns the number of occurences of a byte in a byte sequence.
|
static int |
count(byte[] data,
byte[] value)
Returns the number of occurences of a byte in a byte sequence.
|
static int |
count(byte[] data,
int startIndex,
byte value)
Returns the number of occurences of a byte in a byte sequence, starting at the given offset.
|
static int |
count(byte[] data,
int startIndex,
byte[] value)
Returns the number of occurences of a byte sequence within a byte sequence.
|
static boolean |
endsWith(byte[] data,
byte[] value)
Returns true if a buffer ends with a value.
|
static byte[] |
getBytes(int value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(long value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(short value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(UnsignedInteger value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(UnsignedLong value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(UnsignedShort value)
Similar to BitConverter.GetBytes() of .NET.
|
static byte[] |
getBytes(java.util.UUID uuid)
Converts a UUID to a byte array.
|
static int |
indexOf(byte[] data,
byte value)
Returns the first index of a byte encountered within some data.
|
static int |
indexOf(byte[] data,
byte[] value)
Returns the first index of a byte sequence encountered within some data.
|
static int |
indexOf(byte[] data,
byte[] value,
int occurrence)
Returns the index of the first/second/third/etc.
|
static int |
indexOf(byte[] data,
int startIndex,
byte value)
Returns the first index of a byte encountered within some data.
|
static int |
indexOf(byte[] data,
int startIndex,
byte[] value)
Returns the first index of a byte sequence encountered within some data.
|
static byte[] |
join(byte[] a,
byte[] b)
Joins two byte arrays.
|
static byte[] |
join(java.lang.Iterable<byte[]> arrays)
Joins two or more arrays in the order they were provided.
|
static int |
lastIndexOf(byte[] data,
byte value)
Returns the last index of a byte encountered within some data.
|
static int |
lastIndexOf(byte[] data,
byte[] value)
Returns the last index of a byte sequence encountered within some data.
|
static int |
lastIndexOf(byte[] data,
byte[] value,
int occurrence)
Returns the index of the first/second/third/etc.
|
static int |
lastIndexOf(byte[] data,
int startIndex,
byte value)
Returns the last index of a byte encountered within some data.
|
static int |
lastIndexOf(byte[] data,
int startIndex,
byte[] value)
Returns the last index of a byte sequence encountered within some data.
|
static boolean |
match(byte[] a,
MatchType byteMatch,
byte[] b)
Allows for matching a byte[] to another, using Equals, StartsWith, EndsWith or Contains matching types.
|
static byte[] |
resize(byte[] array,
int length)
Re-sizes an array to the specified size.
|
static byte[] |
reverse(byte[] array)
Reverses an array (in place)
|
static byte[] |
reverseCopy(byte[] array)
Reverses an array (creates a new copy)
|
static boolean |
sequenceEqual(byte[] a,
byte[] b)
Returns true if the byte sequences within two arrays are equal.
|
static boolean |
sequenceEqual(byte[] a,
int startIndexA,
byte[] b,
int startIndexB,
int count)
Returns true if the byte sequences within two arrays are equal
|
static byte[] |
shiftLeft(byte[] data,
int count)
Obfuscation-oriented byte shifting function, shifts individual bytes left, does not check for or handles overflow.
|
static byte[] |
shiftRight(byte[] data,
int count)
Obfuscation-oriented byte shifting function, shifts individual bytes right, does not check for or handles overflow.
|
static java.util.List<byte[]> |
split(byte[] data,
byte separator)
Splits a byte array into parts using the given separator
|
static java.util.List<byte[]> |
split(byte[] data,
byte[] separator)
Splits a byte array into parts using the given separator.
|
static java.util.List<byte[]> |
split(byte[] data,
byte[] separator,
StringSplitOptions options)
Splits a byte array into parts using the given separator.
|
static boolean |
startsWith(byte[] data,
byte[] value)
Returns true if the given byte sequence in data starts with the bytes found in value.
|
static byte[] |
subarray(byte[] buffer,
int startIndex)
Returns a sub-array of the given array
|
static byte[] |
subarray(byte[] buffer,
int startIndex,
int length)
Returns a sub-array of the given array
|
static void |
swap(byte[] array,
int a,
int b)
Swaps two elements in an array.
|
static short |
toInt16(byte[] value)
Inverse function of GetBytes(short)
|
static int |
toInt32(byte[] value)
Inverse function of GetBytes(int)
|
static long |
toInt64(byte[] value)
Inverse function of GetBytes(long)
|
static UnsignedShort |
toUInt16(byte[] value)
Inverse function of GetBytes(UnsignedShort)
|
static UnsignedInteger |
toUInt32(byte[] value)
Inverse function of GetBytes(UnsignedInteger)
|
static UnsignedLong |
toUInt64(byte[] value)
Inverse function of GetBytes(UnsignedLong)
|
public static final boolean LITTLE_ENDIAN
public static void clear(byte[] array)
java.lang.NullPointerException
- An argument is null.public static int count(byte[] data, byte[] value)
java.lang.NullPointerException
- An argument is null.public static int count(byte[] data, int startIndex, byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int count(byte[] data, byte value)
java.lang.NullPointerException
- An argument is null.public static int count(byte[] data, int startIndex, byte value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static boolean endsWith(byte[] data, byte[] value)
java.lang.NullPointerException
- An argument is null.public static byte[] getBytes(short value)
public static byte[] getBytes(UnsignedShort value)
public static byte[] getBytes(int value)
public static byte[] getBytes(UnsignedInteger value)
public static byte[] getBytes(long value)
public static byte[] getBytes(UnsignedLong value)
public static byte[] getBytes(java.util.UUID uuid)
public static int indexOf(byte[] data, byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int indexOf(byte[] data, int startIndex, byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IndexOutOfBoundsException
- An index is out of range.public static int indexOf(byte[] data, byte value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int indexOf(byte[] data, int startIndex, byte value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int indexOf(byte[] data, byte[] value, int occurrence)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static byte[] join(byte[] a, byte[] b)
java.lang.NullPointerException
- An argument is null.public static byte[] join(java.lang.Iterable<byte[]> arrays)
java.lang.NullPointerException
- An argument is nullpublic static int lastIndexOf(byte[] data, byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int lastIndexOf(byte[] data, int startIndex, byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IndexOutOfBoundsException
- An index is out of range.public static int lastIndexOf(byte[] data, byte value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int lastIndexOf(byte[] data, int startIndex, byte value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int lastIndexOf(byte[] data, byte[] value, int occurrence)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static boolean match(byte[] a, MatchType byteMatch, byte[] b)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static byte[] resize(byte[] array, int length)
java.lang.NullPointerException
- Array is nulljava.lang.IllegalArgumentException
- Length is out of rangepublic static byte[] reverse(byte[] array)
java.lang.NullPointerException
- Array is null.public static byte[] reverseCopy(byte[] array)
java.lang.NullPointerException
- Array is null.public static boolean sequenceEqual(byte[] a, byte[] b)
public static boolean sequenceEqual(byte[] a, int startIndexA, byte[] b, int startIndexB, int count)
java.lang.NullPointerException
- An argument is null.java.lang.IndexOutOfBoundsException
- An index is out of bounds.java.lang.IllegalArgumentException
- An argument is out of range.public static byte[] shiftRight(byte[] data, int count)
java.lang.NullPointerException
- An argument is nullpublic static byte[] shiftLeft(byte[] data, int count)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<byte[]> split(byte[] data, byte[] separator)
java.lang.NullPointerException
- An argument is nullpublic static java.util.List<byte[]> split(byte[] data, byte[] separator, StringSplitOptions options)
java.lang.NullPointerException
- An argument is null.public static java.util.List<byte[]> split(byte[] data, byte separator)
java.lang.NullPointerException
- An argument is null.public static boolean startsWith(byte[] data, byte[] value)
java.lang.NullPointerException
- An argument is null.public static byte[] subarray(byte[] buffer, int startIndex)
java.lang.NullPointerException
- An argument is null.java.lang.IndexOutOfBoundsException
- An index is out of bounds.java.lang.IllegalArgumentException
- An argument is out of range.public static byte[] subarray(byte[] buffer, int startIndex, int length)
java.lang.NullPointerException
- An argument is null.java.lang.IndexOutOfBoundsException
- An index is out of bounds.java.lang.IllegalArgumentException
- An argument is out of range.public static void swap(byte[] array, int a, int b)
java.lang.NullPointerException
- Array is nulljava.lang.IndexOutOfBoundsException
- Array indices are out of range.public static short toInt16(byte[] value)
public static UnsignedShort toUInt16(byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static int toInt32(byte[] value)
public static UnsignedInteger toUInt32(byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static long toInt64(byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.public static UnsignedLong toUInt64(byte[] value)
java.lang.NullPointerException
- An argument is null.java.lang.IllegalArgumentException
- An argument is out of range.