public class Bytes
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
arrayEquals(byte[] a1,
int offset1,
int length1,
byte[] a2,
int offset2,
int length2)
Compare two byte array segments for equality.
|
static byte[] |
fromBase64String(java.lang.String s)
Convert a base-64 encoded string into an array of bytes using RFC 4648 rules.
|
static byte[] |
fromHexString(java.lang.String s)
Convert a string of hexadecimal digits to an array of bytes.
|
static int |
hashCode(byte[] a,
int offset,
int length)
Calculate hash code of a byte array segment.
|
static java.lang.String |
toBase64String(byte[] bytes)
Convert an array of bytes into a Base-64 encoded using RFC 4648 rules.
|
static java.lang.String |
toHexString(byte b)
Convert a byte into a two-digit hex string.
|
static java.lang.String |
toHexString(byte[] bytes)
Convert an array into a string of hex digits.
|
static java.lang.String |
toHexString(byte[] bytes,
int offset,
int length)
Convert a portion of an array into a string of hex digits.
|
static java.lang.String |
toString(byte[] bytes)
Convert a byte array into a
String using the
RadixConstants.STANDARD_CHARSET character set. |
static byte[] |
trimLeadingZeros(byte[] bytes)
Trims any leading zero bytes from
bytes until either no
leading zero exists, or only a single zero byte exists. |
public static boolean arrayEquals(byte[] a1, int offset1, int length1, byte[] a2, int offset2, int length2)
a1
- The first array to compareoffset1
- The offset within a1
to begin the comparisonlength1
- The quantity of a1
to comparea2
- The second array to compareoffset2
- The offset within a2
to begin the comparisonlength2
- The quantity of a2
to comparetrue
iff length1 == length2
and a1[offset1 + i] == a2[offset2 + i]
for i
∈ [0, length1)
.public static int hashCode(byte[] a, int offset, int length)
a
- The array for which to calculate the hash code.offset
- The offset within the array to start the calculation.length
- The number of bytes for which to calculate the hash code.public static java.lang.String toString(byte[] bytes)
String
using the
RadixConstants.STANDARD_CHARSET
character set.bytes
- The bytes to convert.public static java.lang.String toHexString(byte b)
Note that digits a-f are output as lower case.
b
- The byte to convertpublic static java.lang.String toHexString(byte[] bytes)
The output string will have length 2*bytes.length
.
Hex digits a-f are encoded as lower case.
bytes
- The bytes to convertpublic static java.lang.String toHexString(byte[] bytes, int offset, int length)
The output string will have length 2*length
.
Hex digits a-f are encoded as lower case.
bytes
- The bytes to convertoffset
- The offset at which to start convertinglength
- The number of bytes to convertpublic static byte[] fromHexString(java.lang.String s)
If the string length is odd, a leading '0' is assumed.
s
- The string to convert to a byte array.java.lang.IllegalArgumentException
- if any character in s is not a hex digitpublic static java.lang.String toBase64String(byte[] bytes)
bytes
- The bytes to encodepublic static byte[] fromBase64String(java.lang.String s)
s
- The string to convertpublic static byte[] trimLeadingZeros(byte[] bytes)
bytes
until either no
leading zero exists, or only a single zero byte exists.bytes
- the byte abytes
with leading zeros removed, if any