### Question:
LinkedBufferInput extends AbstractInput { public void copyReferencedBuffer() { if (link.isEmpty()) { return; } int size = 0; for(ByteBuffer bb : link) { size += bb.remaining(); } if (size == 0) { return; } if (writable >= 0) { ByteBuffer last = link.removeLast(); byte[] copy = new byte[size - last.remaining()]; int off = 0; for(ByteBuffer bb : link) { int len = bb.remaining(); bb.get(copy, off, len); off += len; } link.clear(); link.add(ByteBuffer.wrap(copy)); link.add(last); } else { byte[] copy = new byte[size]; int off = 0; for(ByteBuffer bb : link) { int len = bb.remaining(); bb.get(copy, off, len); off += len; } link.clear(); link.add(ByteBuffer.wrap(copy)); writable = 0; } } LinkedBufferInput(int bufferSize); int read(byte[] b, int off, int len); boolean tryRefer(BufferReferer ref, int len); byte readByte(); void advance(); byte getByte(); short getShort(); int getInt(); long getLong(); float getFloat(); double getDouble(); void feed(byte[] b); void feed(byte[] b, boolean reference); void feed(byte[] b, int off, int len); void feed(byte[] b, int off, int len, boolean reference); void feed(ByteBuffer b); void feed(ByteBuffer buf, boolean reference); void clear(); void copyReferencedBuffer(); int getSize(); void close();  }### Answer:
@Test public void testCopyReferencedBuffer() throws IOException { byte[] data = new byte[16]; data[0] = (byte)4; data[3] = (byte)5; data[6] = (byte)6; data[10] = (byte)7; LinkedBufferInput b = new LinkedBufferInput(32); int n; byte[] buf = new byte[16]; b.feed(data, true); b.feed(data, true); b.feed(data, true); assertEquals(3, b.link.size()); assertEquals(-1, b.writable); b.copyReferencedBuffer(); assertEquals(1, b.link.size()); assertEquals(0, b.writable); n = b.read(buf, 0, 16); assertEquals(n, 16); assertArrayEquals(data, buf); n = b.read(buf, 0, 16); assertEquals(n, 16); assertArrayEquals(data, buf); n = b.read(buf, 0, 16); assertEquals(n, 16); assertArrayEquals(data, buf); }