public class ByteArrayUtil extends Object
| Modifier and Type | Field | Description |
|---|---|---|
static char[] |
hexArray |
|
static int |
LENGTH_OF_INTEGER |
|
static int |
LENGTH_OF_LONG |
| Constructor | Description |
|---|---|
ByteArrayUtil() |
| Modifier and Type | Method | Description |
|---|---|---|
static boolean |
arraysEqual(byte[] a,
int aOffset,
int aLength,
byte[] b,
int bOffset,
int bLength) |
Check if the given two byte arrays are equal or not.
|
static boolean |
arraysEqual(byte[] a,
int aOffset,
int aLength,
String b) |
Check the equality of the contents of byte array with the string
|
static String |
byteArrayToHexString(byte[] bytes) |
Create hex string from the given byte array
|
static String |
byteArrayToHexString(byte[] bytes,
int offset,
int len) |
Create hex string from the given byte array
|
static int |
copyAsHexString(byte[] source,
int sIndex,
int sLength,
byte[] dest,
int dIndex) |
Copy the given byte source array as hex char at the end of the given dest array
For example if the given byte [] contains word 'hello' into it,
the byte array data = {68, 65, 6c, 6c, 6f}
after calling this method it will append '68656c6f' at the end of the given dest array
so after adding dest instance will contain data = {36 38 36 35 36 63 36 63 36 66}
|
static double |
getDoubleValue(byte[] data,
int index,
int numberOfBytes) |
Get a double value from the given byte array and given index.
|
static int |
getIntValue(byte[] data,
int index,
int numberOfBytes) |
Get an integer value from the given byte array and given index using given number of bytes.
|
static long |
getLongValue(byte[] data,
int index,
int numberOfBytes) |
Get a long value from the given byte array and given index using given number of bytes.
|
static int |
getRandomData(byte[] array) |
Fill the given byte array with random data.
|
static int |
getRandomData(byte[] array,
int offset,
int len) |
Fill the given byte array with random data.
|
static int |
getRandomHexData(byte[] data) |
Populate the given byte [] array from the given index with random
hexArray char of given length. |
static int |
getRandomHexData(byte[] data,
int index,
int length) |
Populate the given byte [] array from the given index with random
hexArray char of given length. |
static String |
getString(byte[] data,
int index,
int length) |
When string value is sent from remote side, null string is sent using string 'null'.
|
static byte[] |
hexStringToByteArray(String s) |
Fill the given byte array with converted byte array from given hex string.
|
static int |
hexStringToByteArray(String s,
byte[] destByteArray,
int offset) |
Fill the given byte array with converted byte array from given hex string.
|
static int |
putValue(byte[] data,
int index,
long value,
int numberOfBytes) |
Put a long value in the given index.
|
public static final int LENGTH_OF_INTEGER
public static final int LENGTH_OF_LONG
public static final char[] hexArray
public static String byteArrayToHexString(byte[] bytes)
bytes - byte array from which hex string will be created.public static String byteArrayToHexString(byte[] bytes, int offset, int len)
bytes - byte array from which hex string will be created.offset - starting index of the byte arraylen - length of the byte array that should be converted to hex string.public static byte[] hexStringToByteArray(String s)
s - The hex string that will be converted to byte array.public static int hexStringToByteArray(String s, byte[] destByteArray, int offset)
s - The hex string that will be converted to byte array.destByteArray - This byte array will be filled with the converted bytes from given hex string.offset - starting index of the byte array to be filled.public static int getRandomData(byte[] array)
array - The byte array to be filled.public static int getRandomData(byte[] array,
int offset,
int len)
array - The byte array to be filled.offset - Starting index of the byte array to be filled.len - total number of bytes to be filled.public static int getRandomHexData(byte[] data)
hexArray char of given length.data - this array will be populated with random hex bytes.public static int getRandomHexData(byte[] data,
int index,
int length)
hexArray char of given length.data - this array will be populated with random hex bytes.index - starting index of the byte array to be populatedlength - number or hex byte to be appended.public static int copyAsHexString(byte[] source,
int sIndex,
int sLength,
byte[] dest,
int dIndex)
source - ths byte [] will be copied to dest arraysIndex - source byte [] starting indexsLength - source byte [] length to be copieddest - source byte [] will be copied into this array.dIndex - starting index of dest byte []public static int putValue(byte[] data,
int index,
long value,
int numberOfBytes)
data - byte array where the value should be put.index - starting index of the byte array where the value should be put.value - value that should be put in the given byte array at given index. Value will be added in little-endian
format using LENGTH_OF_LONG bytes.numberOfBytes - Defines the number of bytes required to put the value into byte array.public static int getIntValue(byte[] data,
int index,
int numberOfBytes)
data - byte array from where value will be extracted.index - starting index of the valuenumberOfBytes - Defines the number of bytes that represents the value into byte array.public static long getLongValue(byte[] data,
int index,
int numberOfBytes)
data - byte array from where value will be extracted.index - starting index of the valuenumberOfBytes - Defines the number of bytes that represents the value into byte array.public static double getDoubleValue(byte[] data,
int index,
int numberOfBytes)
data - byte array from where value will be extracted.index - starting index of the valuenumberOfBytes - Defines the number of bytes that represents the value into byte array.public static String getString(byte[] data, int index, int length)
data - byte array from where string value will be extracted.index - starting index of the string value.length - length of the string value.public static boolean arraysEqual(byte[] a,
int aOffset,
int aLength,
byte[] b,
int bOffset,
int bLength)
a - first byte arrayaOffset - starting index of first byte arrayaLength - length of first byte arrayb - second byte arraybOffset - starting index of second byte arraybLength - length of second byte arraypublic static boolean arraysEqual(byte[] a,
int aOffset,
int aLength,
String b)
a - instance of the byte arrayaOffset - offset of the byte arrayaLength - length of the byte arrayb - String to be compared.Copyright © 2025. All rights reserved.