我知道 Stargate 期望将值插入到 HBase 表中以进行 base64 编码。
在形成 HTTP PUT 的 JSON 有效负载之前,我们如何对整数和浮点数等数值进行 base64 编码?
我可以自己解决这个问题,下面是我如何编码整数和双精度值的片段:
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);
}