Package de.unkrig.commons.io.pipe

A pipe is an object to which data can be written and from which data can be read; the data read equals the data previously written.

See:
          Description

Interface Summary
Pipe Pipe.read(byte[], int, int) produces exactly the bytes that were previously written.
PipeUtil.Drainer Drains 'something' by reading data from an input stream.
PipeUtil.Filler Fills 'something' by writing data to an output stream.
PipeUtil.FillerAndDrainer  
PipeUtil.InputOutputStreams A tuple of one InputStream and one OutputStream.
 

Class Summary
AbstractPipe Basic implementation of a pipe.
AbstractRingBuffer Implementation of a pipe by a ring buffer.
PipeFactory The methods of this class create the various Pipe implementations: PipeFactory.byteArrayRingBuffer(int) A pipe which is backed by an (internal) byte array PipeFactory.byteBufferRingBuffer(ByteBuffer) A pipe which is backed by a ByteBuffer PipeFactory.elasticPipe() A Pipe that implements infinite capacity and good performance by first allocating a small in-memory ring buffer, then, if that fills up, a larger one that uses a memory-mapped file, and eventually one based on a random access file with practically unlimited size PipeFactory.elasticPipe(de.unkrig.commons.lang.protocol.ProducerWhichThrows) A Pipe that implements infinite capacity by allocating delegate pipes as needed (and closing them when they are no longer needed) PipeFactory.mappedFileRingBuffer(java.io.File, int, boolean) A pipe which is backed by a memory-mapped file, which will be unmapped and (optionally) deleted when the pipe is closed PipeFactory.mappedTempFileRingBuffer(int) A pipe which is backed by a memory-mapped temporary file, which will be unmapped and deleted when the pipe is closed PipeFactory.randomAccessFileRingBuffer(java.io.File, long, boolean) A pipe which is backed by a RandomAccessFile, which will (optionally) be deleted when the pipe is closed PipeFactory.randomAccessTempFileRingBuffer(long) A pipe which is backed by a temporary RandomAccessFile, which is deleted when the pipe is closed The characteristics of these implementations are as follows:   Performance Resource usage Size limits byteArrayRingBuffer(int) Fast Heap memory 2 GB byteBufferRingBuffer(ByteBuffer.allocate(int)) Fast Heap memory 2 GB byteBufferRingBuffer(ByteBuffer.allocateDirect(int)) Fast Off-heap memory 2 GB mappedFileRingBuffer(File, int, boolean) Medium Low 2 GB, Address space, disk space randomAccessFileRingBuffer(File, long, boolean) Low Low Disk space
PipeUtil Utility methods related to the Pipe interface.
 

Package de.unkrig.commons.io.pipe Description

A pipe is an object to which data can be written and from which data can be read; the data read equals the data previously written.

There are two typical use cases for a pipe:

Buffer
One ore more threads write to and read from the pipe alternatingly and/or simultaneously. If the writers are 'faster' than the readers, the pipe will fill up. If the readers ar faster, the pipe will become empty. An obvious implementation is a 'ring buffer'.
Temporary storage
First data is written to the pipe, then (completely) read back. This could be implemented by a 'linear buffer'; however, since since 'ring buffer' has no significant overhead, there is no reason to implement the 'linear buffer'.
The Pipe interface describes a non-blocking version of a pipe: The write(byte[] buf, int off, int len and read(byte[] buf, int off, int len methods simply return zero iff the pipe is full resp. empty.

PipeUtil.asInputOutputStreams(de.unkrig.commons.io.pipe.Pipe) converts a Pipe into a pair of output stream and input stream which block the calling thread while the pipe is full resp. empty.

The methods of the PipeFactory create various implementations of the Pipe interface.