Java Utililty Methods Convert via ByteBuffer

List of utility methods to do Convert via ByteBuffer

Description

The list of methods to do Convert via ByteBuffer are organized into topic(s).

Method

StringtoGuidString(UUID uuid)
to Guid String
byte[] guidBytes = toGuidBytes(uuid);
String to = toHex(guidBytes);
return to;
StringtoHex(byte[] bytes)
Returns hex-digit (lower case) string.
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    int value = (int) bytes[i] & 0xff;
    if (value < 0x10) {
        buf.append("0");
    buf.append(Integer.toHexString(value));
return buf.toString();
StringtoHexBytes(byte[] bytes)
Converts the given bytes into a hexadecimal representation.
return toHexBytes(bytes, 0, bytes.length);
StringtoHexString(Number n)
to Hex String
if (n == null)
    return "null";
byte[] bytes = new byte[8];
ByteBuffer bytesBuffer = ByteBuffer.wrap(bytes);
LongBuffer longBuffer = bytesBuffer.asLongBuffer();
longBuffer.put(0, n.longValue());
StringBuilder sb = new StringBuilder(16);
for (int i = 0; i < bytes.length; i++) {
...
int[]toInt(byte[] bytes)
to Int
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
IntBuffer buffer = byteBuffer.asIntBuffer();
int ret[] = new int[buffer.capacity()];
buffer.get(ret);
return ret;
inttoInt(byte[] data)
to Int
return ByteBuffer.wrap(data).getInt();
inttoInt(byte[] value)
Convert the first 4 bytes of an array to a big endian int.
if (value == null) {
    return 0;
int val = 0;
if (value.length >= 1) {
    val |= ((value[0] & 0xFF) << 24);
if (value.length >= 2) {
...
inttoInt(final byte lowOrderByte, final byte highOrderByte)
to Int
return toInt(lowOrderByte, highOrderByte, ByteOrder.LITTLE_ENDIAN);
inttoInt(InetAddress address)
Converts ipv4 InetAddress to Integer.
return ByteBuffer.wrap(address.getAddress()).getInt();
int[]toIntArray(byte[] byteArray)
Returns a new integer array using data from the given byte array.
IntBuffer intBuffer = ByteBuffer.wrap(byteArray).asIntBuffer();
int[] intArray = new int[intBuffer.limit()];
intBuffer.get(intArray);
return intArray;