【发布时间】:2014-01-23 16:07:21
【问题描述】:
我知道 Stargate 希望插入到 HBase 表中的值是 base64 编码的。
在形成 HTTP PUT 的 JSON 有效负载之前,我们如何对整数和浮点数等数值进行 base64 编码?
【问题讨论】:
我知道 Stargate 希望插入到 HBase 表中的值是 base64 编码的。
在形成 HTTP PUT 的 JSON 有效负载之前,我们如何对整数和浮点数等数值进行 base64 编码?
【问题讨论】:
我可以自己解决这个问题,下面是我如何编码整数和双精度值的 sn-p:
long t = 11;
String e1 = Base64.encodeBase64String(BigInteger.valueOf(t).toByteArray());
t = 78;
String e2 = Base64.encodeBase64String(BigInteger.valueOf(t).toByteArray());
System.out.println("e1: "+e1+", e2: "+e2);
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
double d = -1.966723;
out.writeDouble(d);
out.flush();
byte[] buf = byteOut.toByteArray();
String e3 = Base64.encodeBase64String(buf);
System.out.println("e3: "+e3);
}
catch(Exception e) {
System.out.println("Exception: "+e);
}
【讨论】: