Class PipeChannel

  • All Implemented Interfaces:
    Closeable, Appendable, AutoCloseable, Readable, Channel, ReadableByteChannel, WritableByteChannel

    public class PipeChannel
    extends Object
    implements ReadableByteChannel, WritableByteChannel, Appendable, Readable, Closeable
    Implements a buffer that provides a slightly more efficient way of writing, and then reading a stream of bytes. To use: PipeChannel pipe = new PipeChannel(); byte[] bytes = {'a','b','c','d'}; pipe.write(bytes); pipe.close(); InputStream in = pipe.getInputStream(); int i = -1; while ((i = in.read()) != -1) {...} By default, closing will automatically cause it to flip over to Read mode, locking the buffer from further writes and setting the read position to 0. Once the Buffer has been fully read, it must be reset, which sets it back into write mode