package gnu.java.nio;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Pipe;
import java.nio.channels.spi.SelectorProvider;
class PipeImpl extends Pipe
{
public static final class SourceChannelImpl extends Pipe.SourceChannel
{
private int native_fd;
public SourceChannelImpl (SelectorProvider selectorProvider,
int native_fd)
{
super (selectorProvider);
this.native_fd = native_fd;
}
protected final void implCloseSelectableChannel()
throws IOException
{
throw new Error ("Not implemented");
}
protected void implConfigureBlocking (boolean blocking)
throws IOException
{
throw new Error ("Not implemented");
}
public final int read (ByteBuffer src)
throws IOException
{
throw new Error ("Not implemented");
}
public final long read (ByteBuffer[] srcs)
throws IOException
{
return read (srcs, 0, srcs.length);
}
public final synchronized long read (ByteBuffer[] srcs, int offset,
int len)
throws IOException
{
if (offset < 0
|| offset > srcs.length
|| len < 0
|| len > srcs.length - offset)
throw new IndexOutOfBoundsException();
long bytesRead = 0;
for (int index = 0; index < len; index++)
bytesRead += read (srcs [offset + index]);
return bytesRead;
}
public final int getNativeFD()
{
return native_fd;
}
}
public static final class SinkChannelImpl extends Pipe.SinkChannel
{
private int native_fd;
public SinkChannelImpl (SelectorProvider selectorProvider,
int native_fd)
{
super (selectorProvider);
this.native_fd = native_fd;
}
protected final void implCloseSelectableChannel()
throws IOException
{
throw new Error ("Not implemented");
}
protected final void implConfigureBlocking (boolean blocking)
throws IOException
{
throw new Error ("Not implemented");
}
public final int write (ByteBuffer dst)
throws IOException
{
throw new Error ("Not implemented");
}
public final long write (ByteBuffer[] srcs)
throws IOException
{
return write (srcs, 0, srcs.length);
}
public final synchronized long write (ByteBuffer[] srcs, int offset, int len)
throws IOException
{
if (offset < 0
|| offset > srcs.length
|| len < 0
|| len > srcs.length - offset)
throw new IndexOutOfBoundsException();
long bytesWritten = 0;
for (int index = 0; index < len; index++)
bytesWritten += write (srcs [offset + index]);
return bytesWritten;
}
public final int getNativeFD()
{
return native_fd;
}
}
private SinkChannelImpl sink;
private SourceChannelImpl source;
public PipeImpl (SelectorProvider provider)
throws IOException
{
super();
VMPipe.init (this, provider);
}
public Pipe.SinkChannel sink()
{
return sink;
}
public Pipe.SourceChannel source()
{
return source;
}
}