package org.msgpack.core.buffer;

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

import static org.msgpack.core.Preconditions.*;

/**
 * {@link MessageBufferInput} adapter for {@link java.nio.channels.ReadableByteChannel}
 */
public class ChannelBufferInput implements MessageBufferInput {

    private final ReadableByteChannel channel;
    private boolean reachedEOF = false;
    private final int bufferSize;

    public ChannelBufferInput(ReadableByteChannel channel) {
        this(channel, 8192);
    }

    public ChannelBufferInput(ReadableByteChannel channel, int bufferSize) {
        this.channel = checkNotNull(channel, "input channel is null");
        checkArgument(bufferSize > 0, "buffer size must be > 0: " + bufferSize);
        this.bufferSize = bufferSize;
    }

    @Override
    public MessageBuffer next() throws IOException {

        if(reachedEOF)
            return null;

        MessageBuffer m = MessageBuffer.newBuffer(bufferSize);
        ByteBuffer b = m.toByteBuffer();
        while(!reachedEOF && b.remaining() > 0) {
            int ret = channel.read(b);
            if(ret == -1) {
                reachedEOF = true;
            }
        }
        b.flip();
        return b.remaining() == 0 ? null : m.slice(0, b.limit());
    }

    @Override
    public void close() throws IOException {
        channel.close();
    }
}

@@ -923,16 +923,18 @@
 chedEOF)
+ %7B
 %0A       
@@ -950,16 +950,26 @@
 rn null;
+%0A        %7D
 %0A%0A      

Fix brace style