简体   繁体   中英

“Byte Patterns” in hbase rowkey design

from Hbase rowkey design

I dont unstand the sample in "Byte Pattern":

 // hash
//
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(Bytes.toBytes(s));
System.out.println("md5 digest bytes length: " + digest.length);    // returns 16

String sDigest = new String(digest);
byte[] sbDigest = Bytes.toBytes(sDigest);
System.out.println("md5 digest as string length: " + sbDigest.length);    // returns 26

why sbDigent.length != digest.length ?

Thank you

in my eclipse, "digest" is 0xE807F1FCF82D132F9BB018CA6738A19F, 16 bytes, so its length is 16.

"sbDigest" is 0xEFBFBD07EFBFBDEFBFBDEFBFBD2D132FEFBFBDEFBFBD18EFBFBD6738EFBFBDEFBFBD,34 bytes, so its length is 34 ( not 26 ).

The root reason is java.lang.String's constructor:

public String(byte[] bytes)

Constructs a new String by decoding the specified array of bytes using the platform's default charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM