【问题标题】:How to insert integer/float as byte arrays into HBase with Stargate REST?如何使用 Stargate REST 将整数/浮点数作为字节数组插入 HBase?
【发布时间】:2014-01-23 16:07:21
【问题描述】:

我知道 Stargate 希望插入到 HBase 表中的值是 base64 编码的。

在形成 HTTP PUT 的 JSON 有效负载之前,我们如何对整数和浮点数等数值进行 base64 编码?

【问题讨论】:

    标签: hbase stargate


    【解决方案1】:

    我可以自己解决这个问题,下面是我如何编码整数和双精度值的 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 2012-06-10
      • 2011-01-09
      • 2019-03-17
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      相关资源
      最近更新 更多