java 實現oracle hextoraw函數

最近在做oracle logminer 歸檔日誌分析,發先hextoraw及其不爽,就用java 從寫了一個

 /**
   * 實現oracle HEXTORAW
   * 
   * @param str
   */
  public byte[] hextoraw(String str) {
    if (str.length() % 2 != 0) {
      throw new RuntimeException("數據格式錯誤");
    }
    int len = str.length();
    byte[] bt = null;
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
      for (int i = 0; i < len / 2; i++) {
        String sub = str.substring(i * 2, (i + 1) * 2);
        Byte b = Byte.parseByte(sub, 16);
        os.write(b);
      }
      bt = os.toByteArray();
    } finally {
      IOUtils.closeQuietly(os);
    }
    return bt;
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章