public class ByteUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static byte[] |
EMPTY_BYTE_ARRAY |
| 构造器和说明 |
|---|
ByteUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
and(byte[] b1,
byte[] b2) |
static byte[] |
booleanToBytes(boolean bool) |
static BigInteger |
byteArrayToBigInteger(byte[] b) |
static int |
byteArrayToInt(byte[] b)
Cast hex encoded value from byte[] to int
Limited to Integer.MAX_VALUE: 2^32-1 (4 bytes)
|
static long |
byteArrayToLong(byte[] b)
Cast hex encoded value from byte[] to int
Limited to Integer.MAX_VALUE: 2^32-1 (4 bytes)
|
static String |
byteArrayToString(byte[] paramBytes)
Parse parameter str
|
static Integer |
bytesToInt(byte[] byteArr)
Trans byteArr to int
|
static int[] |
bytesToInts(byte[] arr,
boolean bigEndian) |
static void |
bytesToInts(byte[] b,
int[] arr,
boolean bigEndian) |
static Short |
bytesToShort(byte[] b)
Trans byteArr to short
|
static String |
convertPublicKeyToFixedHexString(BigInteger key)
Convert to fixed hex string string.
|
static String |
convertToFixedHexString(BigInteger key,
int totalLength,
int expectedLength) |
static byte[] |
hexStringToBytes(String data)
Converts string hex representation to data bytes Accepts following hex: - with or without 0x prefix - with no
leading 0, like 0xabc -> 0x0abc
|
static byte[] |
intsToBytes(int[] arr,
boolean bigEndian) |
static void |
intsToBytes(int[] arr,
byte[] b,
boolean bigEndian) |
static byte[] |
intToBytes(int val)
Converts int value into a byte array.
|
static byte[] |
intToBytesNoLeadZeroes(int val)
Converts a int value into a byte array.
|
static boolean |
isNullOrZeroArray(byte[] array) |
static boolean |
isSingleZero(byte[] array) |
static int |
length(byte[]... bytes) |
static byte[] |
longToBytes(long val)
Converts a long value into a byte array.
|
static String |
nibblesToPrettyString(byte[] nibbles)
Turn nibbles to a pretty looking output string
Example. [ 1, 2, 3, 4, 5 ] becomes '\x11\x23\x45'
|
static String |
oneByteToHexString(byte value) |
static byte[] |
stringToByteArray(String string) |
static String |
toHexString(byte[] data)
Convert a byte-array into a hex String.
|
static String |
toHexString(String data) |
public static byte[] longToBytes(long val)
val - - long value to convertbyte[] of length 8, representing the long valuepublic static byte[] intToBytesNoLeadZeroes(int val)
val - - int value to convertpublic static String toHexString(byte[] data)
Hex.toHexString(byte[]) but allows for
nulldata - - byte-array to convert to a hex-stringnullHex.toHexString(byte[])public static int byteArrayToInt(byte[] b)
Limited to Integer.MAX_VALUE: 2^32-1 (4 bytes)
b - array contains the valuespublic static long byteArrayToLong(byte[] b)
Limited to Integer.MAX_VALUE: 2^32-1 (4 bytes)
b - array contains the valuespublic static String nibblesToPrettyString(byte[] nibbles)
Example. [ 1, 2, 3, 4, 5 ] becomes '\x11\x23\x45'
nibbles - - getting byte of data [ 04 ] and turning it to a '\x04' representationpublic static String oneByteToHexString(byte value)
public static byte[] and(byte[] b1,
byte[] b2)
public static boolean isNullOrZeroArray(byte[] array)
public static boolean isSingleZero(byte[] array)
public static int length(byte[]... bytes)
public static byte[] hexStringToBytes(String data)
data - String like '0xa5e..' or just 'a5e..'public static byte[] intToBytes(int val)
val - - int value to convertbyte[] of length 4, representing the int valuepublic static Integer bytesToInt(byte[] byteArr)
byteArr - public static byte[] intsToBytes(int[] arr,
boolean bigEndian)
public static int[] bytesToInts(byte[] arr,
boolean bigEndian)
public static void bytesToInts(byte[] b,
int[] arr,
boolean bigEndian)
public static void intsToBytes(int[] arr,
byte[] b,
boolean bigEndian)
public static Short bytesToShort(byte[] b)
b - public static String byteArrayToString(byte[] paramBytes)
paramBytes - paramBytespublic static BigInteger byteArrayToBigInteger(byte[] b)
public static byte[] stringToByteArray(String string)
public static byte[] booleanToBytes(boolean bool)
public static String convertPublicKeyToFixedHexString(BigInteger key)
key - the keypublic static String convertToFixedHexString(BigInteger key, int totalLength, int expectedLength)
Copyright © 2022. All rights reserved.