/*
 ** 2015 March 06
 **
 ** The author disclaims copyright to this source code. In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.io.buffer.source;

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

/**
 *
 * @author Nico Bergemann <barracuda415 at yahoo.de>
 */
public class BufferedSourceChannel implements ByteChannel {
    
    private final BufferedSource buf;
    private boolean open;
    
    public BufferedSourceChannel(BufferedSource buf) {
        this.buf = buf;
    }

    @Override
    public int read(ByteBuffer dst) throws IOException {
        return buf.read(dst);
    }

    @Override
    public int write(ByteBuffer src) throws IOException {
        return buf.write(src);
    }
    
    @Override
    public boolean isOpen() {
        return open;
    }

    @Override
    public void close() throws IOException {
        open = false;
        buf.flush();
    }
}

@@ -424,16 +424,124 @@
 Channel;
+%0Aimport java.nio.channels.NonReadableChannelException;%0Aimport java.nio.channels.NonWritableChannelException;
 %0A%0A/**%0A *
@@ -881,32 +881,50 @@
 s IOException %7B%0A
+        try %7B%0A    
         return b
@@ -937,16 +937,129 @@
 d(dst);%0A
+        %7D catch (NonReadableSourceException ex) %7B%0A            throw new NonReadableChannelException();%0A        %7D%0A
     %7D%0A%0A 
@@ -1121,32 +1121,50 @@
 s IOException %7B%0A
+        try %7B%0A    
         return b
@@ -1178,16 +1178,129 @@
 e(src);%0A
+        %7D catch (NonWritableSourceException ex) %7B%0A            throw new NonWritableChannelException();%0A        %7D%0A
     %7D%0A  

Convert read-only/write-only exceptions