最近在做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;
}