|
|
@@ -57,11 +57,11 @@ public final class FormatHex {
|
|
|
try {
|
|
|
int n= raw.length;
|
|
|
if(n > 0) {
|
|
|
- append(target, raw[0]);
|
|
|
+ appendByte(target, raw[0]);
|
|
|
}
|
|
|
for(int i=1; i<n; i++) {
|
|
|
target.append(' ');
|
|
|
- append(target, raw[i]);
|
|
|
+ appendByte(target, raw[i]);
|
|
|
}
|
|
|
return target;
|
|
|
} catch (IOException cause) {
|
|
|
@@ -69,10 +69,36 @@ public final class FormatHex {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void append(Appendable target, byte value) throws IOException {
|
|
|
- int ivalue = value & 0xFF;
|
|
|
- target.append(HC_TABLE[ivalue >>> 4]);
|
|
|
- target.append(HC_TABLE[ivalue & 0xF]);
|
|
|
+ public static void appendByte(Appendable target, byte value) {
|
|
|
+ try {
|
|
|
+ int ivalue = value & 0xFF;
|
|
|
+ target.append(HC_TABLE[ivalue >>> 4]);
|
|
|
+ target.append(HC_TABLE[ivalue & 0xF]);
|
|
|
+ } catch (IOException cause) {
|
|
|
+ throw new UncheckedIOException(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void appendChar(Appendable target, char value) {
|
|
|
+ try {
|
|
|
+ System.out.println(">>>>> " + (int)value);
|
|
|
+ int ivalue = value & 0xFFFF;
|
|
|
+ target.append(HC_TABLE[(ivalue >>> 12) & 0xF]);
|
|
|
+ target.append(HC_TABLE[(ivalue >>> 8) & 0xF]);
|
|
|
+ target.append(HC_TABLE[(ivalue >>> 4) & 0xF]);
|
|
|
+ target.append(HC_TABLE[(ivalue & 0xF)]);
|
|
|
+ } catch (IOException cause) {
|
|
|
+ throw new UncheckedIOException(cause);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static char parseChar(CharSequence text, int index) {
|
|
|
+ byte a = CH_TABLE[text.charAt(index++)];
|
|
|
+ byte b = CH_TABLE[text.charAt(index++)];
|
|
|
+ byte c = CH_TABLE[text.charAt(index++)];
|
|
|
+ byte d = CH_TABLE[text.charAt(index++)];
|
|
|
+
|
|
|
+ return (char) ((a << 12) | (b << 8) | (c << 4) | (d));
|
|
|
}
|
|
|
|
|
|
public static byte[] parse(CharSequence text) {
|