[HBase] convert long value to bytes

Java code:

public static void main(String[] args) {
    String stringValue = Bytes.toStringBinary(Bytes.toBytes(1532080782183l));
    System.out.println(stringValue);
    Long longValue = Bytes.toLong(Bytes.toBytesBinary(stringValue));
    System.out.println(longValue);
}

HBase shell command:

hbase(main):056:0> Bytes.toStringBinary(Bytes.to_bytes(1532080782183))
=> "\\x00\\x00\\x01d\\xB7!{g"
hbase(main):057:0> Bytes.toLong("\x00\x00\x01d\xB7!{g".to_java_bytes)
=> 1532080782183
This entry was posted in HBase, Java. Bookmark the permalink.