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