package org.xnio.conduits;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.xnio.Buffers;
import org.xnio.channels.StreamSourceChannel;
public final class MessageStreamSinkConduit extends AbstractSinkConduit<MessageSinkConduit> implements StreamSinkConduit {
public MessageStreamSinkConduit(final MessageSinkConduit next) {
super(next);
}
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
return src.transferTo(position, count, new ConduitWritableByteChannel(this));
}
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException {
return Conduits.transfer(source, count, throughBuffer, this);
}
public int write(final ByteBuffer src) throws IOException {
final int remaining = src.remaining();
return next.send(src) ? remaining : 0;
}
public long write(final ByteBuffer[] srcs, final int offs, final int len) throws IOException {
final long remaining = Buffers.remaining(srcs, offs, len);
return next.send(srcs, offs, len) ? remaining : 0L;
}
@Override
public int writeFinal(ByteBuffer src) throws IOException {
return Conduits.writeFinalBasic(this, src);
}
@Override
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException {
return Conduits.writeFinalBasic(this, srcs, offset, length);
}
}