@Test public void testAppendBytes() { StringBuilder sb = new StringBuilder(); byte[] data = {0, '\\', 'x', -0x01}; DefaultFormatter.appendValue(sb, new Value()); assertEquals("", sb.toString()); DefaultFormatter.appendText(sb, new Text(data)); assertEquals("\\x00\\\\x\\xFF", sb.toString()); }
static StringBuilder appendBytes(StringBuilder sb, byte[] ba, int offset, int len) { for (int i = 0; i < len; i++) { int c = 0xff & ba[offset + i]; if (c == '\\') sb.append("\\\\"); else if (c >= 32 && c <= 126) sb.append((char) c); else sb.append("\\x").append(String.format("%02X", c)); } return sb; }
DefaultFormatter implements Formatter { static StringBuilder appendBytes(StringBuilder sb, byte[] ba, int offset, int len) { for (int i = 0; i < len; i++) { int c = 0xff & ba[offset + i]; if (c == '\\') sb.append("\\\\"); else if (c >= 32 && c <= 126) sb.append((char) c); else sb.append("\\x").append(String.format("%02X", c)); } return sb; } }
DefaultFormatter implements Formatter { static StringBuilder appendBytes(StringBuilder sb, byte[] ba, int offset, int len) { for (int i = 0; i < len; i++) { int c = 0xff & ba[offset + i]; if (c == '\\') sb.append("\\\\"); else if (c >= 32 && c <= 126) sb.append((char) c); else sb.append("\\x").append(String.format("%02X", c)); } return sb; }  }
DefaultFormatter implements Formatter { static StringBuilder appendBytes(StringBuilder sb, byte[] ba, int offset, int len) { for (int i = 0; i < len; i++) { int c = 0xff & ba[offset + i]; if (c == '\\') sb.append("\\\\"); else if (c >= 32 && c <= 126) sb.append((char) c); else sb.append("\\x").append(String.format("%02X", c)); } return sb; }  @Override void initialize(Iterable<Entry<Key,Value>> scanner, FormatterConfig config); @Override boolean hasNext(); @Override String next(); @Override void remove(); static String formatEntry(Entry<Key,Value> entry, boolean showTimestamps); static String formatEntry(Entry<Key,Value> entry, DateFormat timestampFormat); String formatEntry(Entry<Key,Value> entry); static String formatEntry(Entry<Key,Value> entry, FormatterConfig config); static StringBuilder appendText(StringBuilder sb, Text t, int shownLength); Iterator<Entry<Key,Value>> getScannerIterator(); }
DefaultFormatter implements Formatter { static StringBuilder appendBytes(StringBuilder sb, byte[] ba, int offset, int len) { for (int i = 0; i < len; i++) { int c = 0xff & ba[offset + i]; if (c == '\\') sb.append("\\\\"); else if (c >= 32 && c <= 126) sb.append((char) c); else sb.append("\\x").append(String.format("%02X", c)); } return sb; }  @Override void initialize(Iterable<Entry<Key,Value>> scanner, FormatterConfig config); @Override boolean hasNext(); @Override String next(); @Override void remove(); static String formatEntry(Entry<Key,Value> entry, boolean showTimestamps); static String formatEntry(Entry<Key,Value> entry, DateFormat timestampFormat); String formatEntry(Entry<Key,Value> entry); static String formatEntry(Entry<Key,Value> entry, FormatterConfig config); static StringBuilder appendText(StringBuilder sb, Text t, int shownLength); Iterator<Entry<Key,Value>> getScannerIterator();  }