package pw.koj.jetstreem.core;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.Channel;
import java.nio.channels.ReadableByteChannel;
import java.io.IOException;

public class ChannelReadBuffer extends ChannelBuffer {
    public ChannelReadBuffer(Channel ch) {
        super(ch);
    }

    public int read() throws IOException {
        ReadableByteChannel c = (ReadableByteChannel)this.ch;
        return c.read(this.buf);
    }

    public void getChar(char[] ch) {
        this.buf.asCharBuffer().get(ch);
    }

    public char[] subCharSequence(char ch) {
        int start;
        int end;
        CharBuffer cbuf = this.buf.asCharBuffer();

        start = cbuf.position();
        end = cbuf.limit();
        int n;
        for (n = start; n <= end; n++) {
            if (cbuf.get(n) == ch) break;
        }

        if (n > end) {
            return null;
        }
        else {
            char[] c = new char[n - start + 1];
            cbuf.get(c);
            return c;
        }
    }

}


@@ -245,16 +245,53 @@
 uffer %7B%0A
+    private InputPipeThread inPipe;%0A%0A
     publ
@@ -343,32 +343,305 @@
 per(ch);%0A    %7D%0A%0A
+    public ChannelReadBuffer(Channel ch, InputPipeThread inPipe) %7B%0A        super(ch);%0A        this.inPipe = inPipe;%0A    %7D%0A%0A    public boolean hasInputPipe() %7B%0A        return this.inPipe != null;%0A    %7D%0A%0A    public void startInputPipe() %7B%0A        this.inPipe.start();%0A    %7D%0A%0A
     public int r

add member inPipe to ChannelReadBuffer