package org.xnio.conduits;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.TimeUnit;
import org.xnio.ChannelListener;
import org.xnio.XnioIoThread;
import org.xnio.XnioWorker;
import org.xnio.channels.StreamSinkChannel;
import org.xnio.channels.StreamSourceChannel;
public final class StreamSinkChannelWrappingConduit implements StreamSinkConduit {
private final StreamSinkChannel channel;
public StreamSinkChannelWrappingConduit(final StreamSinkChannel channel) {
this.channel = channel;
}
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
return channel.transferFrom(src, position, count);
}
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException {
return channel.transferFrom(source, count, throughBuffer);
}
public int write(final ByteBuffer src) throws IOException {
return channel.write(src);
}
public long write(final ByteBuffer[] srcs, final int offs, final int len) throws IOException {
return channel.write(srcs, offs, len);
}
@Override
public int writeFinal(ByteBuffer src) throws IOException {
return channel.writeFinal(src);
}
@Override
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException {
return channel.writeFinal(srcs, offset, length);
}
public void terminateWrites() throws IOException {
channel.shutdownWrites();
}
public boolean isWriteShutdown() {
return ! channel.isOpen();
}
public void resumeWrites() {
channel.resumeWrites();
}
public void suspendWrites() {
channel.suspendWrites();
}
public void wakeupWrites() {
channel.wakeupWrites();
}
public boolean isWriteResumed() {
return channel.isWriteResumed();
}
public void awaitWritable() throws IOException {
channel.awaitWritable();
}
public void awaitWritable(final long time, final TimeUnit timeUnit) throws IOException {
channel.awaitWritable(time, timeUnit);
}
public XnioIoThread getWriteThread() {
return channel.getIoThread();
}
public void setWriteReadyHandler(final WriteReadyHandler handler) {
channel.getWriteSetter().set(new ChannelListener<StreamSinkChannel>() {
public void handleEvent(final StreamSinkChannel channel) {
handler.writeReady();
}
});
}
public void truncateWrites() throws IOException {
channel.close();
}
public boolean flush() throws IOException {
return channel.flush();
}
public XnioWorker getWorker() {
return channel.getWorker();
}
}