fan*_*ndi 3 java byte hadoop hbase
我将以下行存储在HBase表中
DIEp(^o^)q3 column=DIE:ID, timestamp=1346194191174, value=\x00\x00\x00\x01
Run Code Online (Sandbox Code Playgroud)
我试图访问该值并将其转换为应该是的字符串表示形式1
,但是当我cat
将此文件(我的输出重定向到)时,我没有得到正确的字符串表示形式
cat /hadoop/logs/userlogs/job_201209121654_0027/attempt_201209121654_0027_m_000000_0/stdout
Run Code Online (Sandbox Code Playgroud)
我有类似垃圾的东西 NUL NUL NUL SOH
下面是我正在使用的代码片段.
byte[] result1 = value.getValue("DIE".getBytes(), "ID".getBytes());
String myresult = Bytes.toString(result1);
System.out.println(myresult);
Run Code Online (Sandbox Code Playgroud)
字符串转换的标准HBase方式是Bytes.toBytes(string)和Bytes.toString(bytes).但Jon Skeet是正确的,因为您需要考虑如何将数据放入列中.如果使用Bytes.toBytes(int),则需要在转换为字符串之前将字节转换回整数.