Utilspublic class Utils extends Object This class implements miscellaneous utility methods including
those used for conversion of BigIntegers to byte arrays,
hexadecimal printing of byte arrays etc. |
Fields Summary |
---|
private static char[] | hcHexadecimal digits. |
Methods Summary |
---|
public static boolean | byteMatch(byte[] a, int aOff, byte[] b, int bOff, int len)Checks if two byte arrays match.
if ((a.length < aOff + len) ||
(b.length < bOff + len)) return false;
for (int i = 0; i < len; i++) {
if (a[i + aOff] != b[i + bOff])
return false;
}
return true;
| public static java.lang.String | hexEncode(byte[] b, int off, int len)Converts a subsequence of bytes in a byte array into a
corresponding string of hexadecimal digits, each separated by a ":".
return new String(hexEncodeToChars(b, off, len));
| public static java.lang.String | hexEncode(byte[] b)Converts a byte array into a corresponding string of hexadecimal
digits. This is equivalent to hexEncode(b, 0, b.length).
if (b == null)
return ("");
else
return hexEncode(b, 0, b.length);
| public static char[] | hexEncodeToChars(byte[] b, int off, int len)Converts a subsequence of bytes in a byte array into a
corresponding string of hexadecimal digits, each separated by a ":".
char[] r;
int v;
int i;
int j;
if ((b == null) || (len == 0)) {
return new char[0];
}
if ((off < 0) || (len < 0)) {
throw new ArrayIndexOutOfBoundsException();
}
if (len == 1) {
r = new char[len * 2];
} else {
r = new char[(len * 3) - 1];
}
for (i = 0, j = 0; ; ) {
v = b[off + i] & 0xff;
r[j++] = hc[v >>> 4];
r[j++] = hc[v & 0x0f];
i++;
if (i >= len) {
break;
}
r[j++] = ':";
}
return r;
| public static byte[] | longToBytes(long n)Converts a long value to a cooresponding 8-byte array
starting with the most significant byte.
byte[] b = new byte[8];
for (int i = 0; i < 64; i += 8) {
b[i >> 3] = (byte) ((n >> (56 - i)) & 0xff);
}
return b;
|
|