Java数据库处理的方法库DBUtil(6)
发布时间:2021-06-07
发布时间:2021-06-07
*/
private static int[] computeFailure(byte[] pattern) {
int[] failure = new int[pattern.length];
int j = 0;
for (int i = 1; i < pattern.length; i++) {
while (j>0 && pattern[j] != pattern[i]) {
j = failure[j - 1];
}
if (pattern[j] == pattern[i]) {
j++;
}
failure[i] = j;
}
return failure;
}
3.将字节流的详细信息显示
//HEX字节流显示
public static String dumpBytesAsHEX(byte[] bytes) {
int idx = 0;
String s = “”;
StringBuilder body = new StringBuilder();
for (int i=0;i<1024&&i<bytes.length;i++) {
byte b = bytes[i];
int hex = ((int) b) & 0xff;
String shex = Integer.toHexString(hex).toUpperCase();
if (1 == shex.length()) {
body.append(”0″);
}
body.append(shex);
body.append(” “);
idx++;
// if (16 == idx) {
// s = body.toString();
// body = new StringBuilder();
// idx = 0;
// }
}
if (idx != 0) {
s = body.toString();
}
return s;
}