public static String dump(ByteBuffer buffer, int pos, int limit)
    {
        int oldpos = buffer.position();
        int oldlimit = buffer.limit();
        buffer.limit(limit).position(pos);

        StringBuilder builder = new StringBuilder("[");
        for (int idx = buffer.position(); idx < buffer.limit(); ++idx) {
            builder.append(buffer.get(idx));
            builder.append(',');
        }
        builder.append(']');

        buffer.limit(oldlimit).position(oldpos);
        return builder.toString();
    }
@Test
    public void testDump()
    {
        byte[] array = new byte[10];
        ByteBuffer buffer = ByteBuffer.wrap(array);
        String dump = Utils.dump(buffer, 0, 10);
        assertThat(dump, is("[0,0,0,0,0,0,0,0,0,0,]"));
    }