public static void hexDump(PrintStream ps, ByteBuffer bb) {
        int inLine = 0;

        for (int pos=0; pos < bb.remaining(); pos++) {
            final int b = bb.get(bb.position() + pos) & 0xff;

            if (inLine == 0) ps.print(hexOffset(pos, 6));

            ps.print(Character.forDigit(b / 16, 16));
            ps.print(Character.forDigit(b % 16, 16));
            ps.print(" ");

            inLine++;

            if (inLine == 8) ps.print("- ");

            if (inLine >= 16) {
                ps.print(": ");
                for (int i=0; i < 16; i++) {
                    final byte get = bb.get(bb.position() + (pos - 15 + i));

                    ps.print(getChar(get));
                }

                ps.println();
                inLine = 0;
            }
        }

        if (inLine > 0) {

            for (int i=0; i < (16 - inLine); i++)
                ps.print("   ");
            if (inLine < 8) ps.print("  ");
            ps.print(": ");

            for (int i=0; i < inLine; i++) {
                final byte get = bb.get(
                        bb.position() + bb.remaining() - inLine + i);

                ps.print(getChar(get));
            }

            ps.println();
        }
    }