`
tianyalinfeng
  • 浏览: 442606 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

blogToString & stringToBlob

    博客分类:
  • Java
 
阅读更多

/**
  * transfer blob to string
  *
  * @param blob
  * @return string
  */
 private String blobToString(Blob blob) {

  try {
   byte[] compressed = blob.getBytes(1, (int) blob.length());
   byte[] uncompressed = Snappy.uncompress(compressed);
   String result = new String(uncompressed, "UTF-8");

   return result;
  } catch (Exception ex) {
   ex.printStackTrace();
  }
  return null;
 }

 /**
  * transfer string to blob
  *
  * @param tmp
  * @return blob
  */
 public Blob stringToBlob(String tmp) {
  try {
   byte[] b = Snappy.compress((tmp).getBytes("UTF-8"));
     return new javax.sql.rowset.serial.SerialBlob(b);
  } catch (Exception ex) {
   ex.printStackTrace();
  }

  return null;
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics