de.unkrig.commons.io.pipe
Class PipeUtil

java.lang.Object
  extended by de.unkrig.commons.io.pipe.PipeUtil

public final class PipeUtil
extends java.lang.Object

Utility methods related to the Pipe interface.


Nested Class Summary
static interface PipeUtil.Drainer
          Drains 'something' by reading data from an input stream.
static interface PipeUtil.Filler
          Fills 'something' by writing data to an output stream.
static interface PipeUtil.FillerAndDrainer
           
static interface PipeUtil.InputOutputStreams
          A tuple of one InputStream and one OutputStream.
 
Method Summary
static PipeUtil.InputOutputStreams asInputOutputStreams(Pipe pipe)
          Creates and returns a pair of output stream and input stream which write to and read from the given pipe.
static Pipe deleteFileOnClose(Pipe delegate, java.io.File file)
           
static Pipe onClose(Pipe delegate, RunnableWhichThrows<java.io.IOException> runnable)
           
static void temporaryStorage(PipeUtil.FillerAndDrainer fillerAndDrainer)
          Convenience method for temporaryStorage(Filler, Drainer) when the filler wants to pass information to the drainer.
static void temporaryStorage(PipeUtil.Filler filler, PipeUtil.Drainer drainer)
          Creates a temporary PipeFactory.elasticPipe(), invokes the filler (which fills the pipe), then invokes the drainer (which drains the pipe), and eventually closes the pipe.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asInputOutputStreams

public static PipeUtil.InputOutputStreams asInputOutputStreams(Pipe pipe)
Creates and returns a pair of output stream and input stream which write to and read from the given pipe. The streams block the calling thread while the pipe is full resp. empty.

Closing the output stream indicates an end-of-input condition to the input stream.

Closing the input stream closes the pipe, and the next write attempt to the output stream will cause an EOFException.


deleteFileOnClose

public static Pipe deleteFileOnClose(Pipe delegate,
                                     java.io.File file)
Returns:
A pipe which forwards all operations to the given delegate, and, in addition, deletes the given file on Pipe.close()

onClose

public static Pipe onClose(Pipe delegate,
                           RunnableWhichThrows<java.io.IOException> runnable)
Returns:
A pipe which forwards all operations to the given delegate, and, in addition, runs the given runnable on Pipe.close() AFTER having closed the delegate

temporaryStorage

public static void temporaryStorage(PipeUtil.FillerAndDrainer fillerAndDrainer)
                             throws java.io.IOException
Convenience method for temporaryStorage(Filler, Drainer) when the filler wants to pass information to the drainer.

Throws:
java.io.IOException

temporaryStorage

public static void temporaryStorage(PipeUtil.Filler filler,
                                    PipeUtil.Drainer drainer)
                             throws java.io.IOException
Creates a temporary PipeFactory.elasticPipe(), invokes the filler (which fills the pipe), then invokes the drainer (which drains the pipe), and eventually closes the pipe.

Throws:
java.io.IOException