protected static void printBuffer(RingBuffer buf) { byte[] buffer = buf.getBuffer(); for (int i = 0; i < buffer.length; i++) { if (buffer[i] >= 0x20 && buffer[i] < 0x7F) { try { System.out.print(" " + new String(buffer, i, 1, "ASCII")); } catch (UnsupportedEncodingException e) { } } else if (buffer[i] >= 7 && buffer[i] <= 13) { System.out.print("\\" + backslashEscapes.charAt(buffer[i] - 7)); } else { System.out.print(String.format("%02x", buffer[i])); } System.out.print(" "); } System.out.println(); int pos = buf.getPos(); int len = buf.getLen(); int cap = buf.getCapacity(); for (int i = 0; i < cap; i++) { if ((i >= pos && i < pos + len) || (pos + len > cap && i < (pos + len) % cap)) { if (i == pos) { System.out.print("-^-"); } else { System.out.print("---"); } } else if (i == pos) { System.out.print(" ^ "); } else { System.out.print(" "); } } System.out.println("\n"); // two lines }