Java Utililty Methods Byte Array Create

List of utility methods to do Byte Array Create

Description

The list of methods to do Byte Array Create are organized into topic(s).

Method

byte[]toBytes(long number)
to Bytes
long temp = number;
byte[] b = new byte[8];
for (int i = 0; i < b.length; i++) {
    b[i] = new Long(temp & 0xff).byteValue();
    temp = temp >> 8;
return b;
byte[]toBytes(long size)
to Bytes
byte[] bytes = new byte[8];
bytes[0] = (byte) ((size >> 56) & 0xff);
bytes[1] = (byte) ((size >> 48) & 0xff);
bytes[2] = (byte) ((size >> 40) & 0xff);
bytes[3] = (byte) ((size >> 32) & 0xff);
bytes[4] = (byte) ((size >> 24) & 0xff);
bytes[5] = (byte) ((size >> 16) & 0xff);
bytes[6] = (byte) ((size >> 8) & 0xff);
...
byte[]toBytes(long v, byte[] writeBuffer, int o)
to Bytes
writeBuffer[o + 0] = (byte) (v >>> 56);
writeBuffer[o + 1] = (byte) (v >>> 48);
writeBuffer[o + 2] = (byte) (v >>> 40);
writeBuffer[o + 3] = (byte) (v >>> 32);
writeBuffer[o + 4] = (byte) (v >>> 24);
writeBuffer[o + 5] = (byte) (v >>> 16);
writeBuffer[o + 6] = (byte) (v >>> 8);
writeBuffer[o + 7] = (byte) (v >>> 0);
...
byte[]toBytes(long val)
to Bytes
return toBytes(val, 8);
byte[]toBytes(long value)
Convert a long number to a bytes array.
byte[] memory = new byte[8];
toBytes(value, memory, 0);
return memory;
byte[]toBytes(long value)
to Bytes
return new byte[] { (byte) (value >>> 56), (byte) (value >>> 48), (byte) (value >>> 40),
        (byte) (value >>> 32), (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8),
        (byte) value };
byte[]toBytes(long value)
Convert long to 4 bytes array.
byte[] result = new byte[8];
result[0] = (byte) (value >> 56);
result[1] = (byte) (value >> 48);
result[2] = (byte) (value >> 40);
result[3] = (byte) (value >> 32);
result[4] = (byte) (value >> 24);
result[5] = (byte) (value >> 16);
result[6] = (byte) (value >> 8);
...
byte[]toBytes(long value, int numBytes)
to Bytes
byte[] bytes = new byte[numBytes];
for (int i = numBytes - 1; i > 0; i--) {
    bytes[i] = (byte) value;
    value >>>= 8;
bytes[0] = (byte) value;
return bytes;
byte[]toBytes(long... values)
to Bytes
byte[] array = new byte[8 * values.length];
for (int i = 0; i < values.length; i++) {
    toBytes(values[i], array, 8 * i);
return array;
byte[]toBytes(Object objValue)
to Bytes
if (objValue != null) {
    if (objValue instanceof byte[]) {
        return (byte[]) objValue;
    } else {
        return objValue.toString().getBytes();
} else
    return null;
...