package pw.koj.jetstreem.core;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.Channel;

public class ChannelBuffer {
    public static final int BUF_SIZE = 4096;
    protected Channel ch;
    protected ByteBuffer buf;

    public ChannelBuffer(Channel ch) {
        this.ch = ch;
        this.buf = ByteBuffer.allocateDirect(BUF_SIZE);
    }

    public Channel ch() {
        return this.ch;
    }

    public ByteBuffer buf() {
        return this.buf;
    }

    public boolean hasRemaining() {
        return this.buf.hasRemaining();
    }

    public ByteBuffer get(byte[] dst) {
        return this.buf.get(dst);
    }

    public int remaining() {
        return this.buf.remaining();
    }

    public Buffer clear() {
        return this.buf.clear();
    }

}


@@ -791,11 +791,326 @@
 %0A    %7D%0A%0A
+    public void bufMove(int to, int from, int len) %7B%0A        int toIndex = to;%0A        int fromIndex = from;%0A%0A        for (int i = len; i %3E 0; i--, toIndex++, fromIndex++) %7B%0A            this.buf.put(toIndex, this.buf.get(fromIndex));%0A        %7D%0A%0A        this.buf.position(0);%0A        this.buf.limit(len - 1);%0A    %7D%0A%0A
 %7D%0A%0A

add bufMove() to ChannelBuffer