LinkBuffer { public List<ByteBuffer> getBuffers() { int size = buffers.size() + (current != null ? 1 : 0); List<ByteBuffer> copy = new ArrayList<ByteBuffer>(size); for (ByteBuffer b : buffers) { copy.add(b.duplicate()); } if (current != null) { ByteBuffer duplicate = current.duplicate(); duplicate.flip(); copy.add(duplicate); } return Collections.unmodifiableList(copy); } LinkBuffer();  LinkBuffer(int allocSize); long size(); List<ByteBuffer> getBuffers(); List<ByteBuffer> finish(); LinkBuffer writeByte(final byte value); LinkBuffer writeInt16(final int value); LinkBuffer writeInt16LE(final int value); LinkBuffer writeInt32(final int value); LinkBuffer writeInt32LE(final int value); LinkBuffer writeInt64(final long value); LinkBuffer writeInt64LE(final long value); LinkBuffer writeVarInt32(int value); LinkBuffer writeVarInt64(long value); LinkBuffer writeDouble(final double value); LinkBuffer writeFloat(final float value); LinkBuffer writeByteArray(final byte[] value,
            final int offset, final int length); LinkBuffer writeByteArray(final byte[] value); LinkBuffer writeByteBuffer(ByteBuffer buf); static final int DEFAULT_BUFFER_SIZE; final int allocSize; }
@Test public void testGetBuffers() throws Exception { LinkBuffer b = new LinkBuffer(8); b.writeInt32(42); b.writeInt32(43); b.writeInt32(44); List<ByteBuffer> buffers = b.getBuffers(); assertEquals(2, buffers.size()); assertEquals(8, buffers.get(0).remaining()); assertEquals(4, buffers.get(1).remaining()); assertEquals(42, buffers.get(0).getInt()); assertEquals(43, buffers.get(0).getInt()); assertEquals(44, buffers.get(1).getInt()); }