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;
        }
    }