commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smiley <DSMI...@mitre.org>
Subject [io] PipedUtils addition for reversing OutputStreams into InputStreams
Date Mon, 18 Jul 2005 22:22:03 GMT
Greetings.  I'm new to the list and I'd like to submit an addition to  
commons-io.

I developed some nifty code that takes an OutputStream and sort of  
reverses it as if it were an InputStream.  Error passing and handling  
close is dealt with.  It needs another thread to do the work which  
runs in parallel.  It uses Piped streams.  I created this because I  
had to conform GZIPOutputStream to my framework which demanded an  
InputStream.  The code works.  My code uses JDK 1.5 to take advantage  
of the nice ExecutorService interface.  Here's some Javadoc and the  
method signature:

     /**
      * For reversing an OutputStream into an InputStream.  Useful  
for OutputStreams that
      * alters what is written.  This works via another thread to  
shuffle
      * the data on the other side of a PipedOutputStream.
      * <p>
      * Sample usage:
      * <pre>
      * PipedOutputStream pos = new PipedOutputStream();
      * //wrap pos with buffer since GZIP's c'tor below writes to  
pipe, but pipe isn't
      * //  ready yet.
      * GZIPOutputStream gzo = new GZIPOutputStream(
      *  new BufferedOutputStream(pos,512) );
      * return Scrap.reverseOutputStream( executor, in, pos, gzo );
      * </pre>
      *
      * All arguments musn't be null.
      *
      * @param executor Will call <code>submit()</code> to start  
shuffling the data.
      * @param origin The underlying InputStream where the data is  
coming from.
      * @param pos This is the underlying stream where <code>wrapout</ 
code> writes to.
      *   Callers should create this and will typically use it as a  
constructor argument
      *   to <code>wrapout</code>.  Callers don't need to close this  
stream.
      * @param wrapout Typically a {@link FilterOutputStream} that  
typically alters the
      *  written stream.  Callers don't need to close this stream.
      * @return An InputStream that wraps the results of  
<code>wrapout</code> that came
      *   from <code>origin</code>.  Closing this stream will close  
<code>origin</code>.
      *   If any of <code>origin</code> or <code>wrapout</code>  
interactions cause an
      *   {@link IOException} to be thrown then the next operation  
method invoked on
      *   this class that throws an IOException will throw that  
exception, indirectly.
      */
     public static InputStream reverseOutputStream(
             ExecutorService executor,
             final InputStream origin, final PipedOutputStream pos,
             final OutputStream wrapout)


I've thought of wrapping this method, a companion method, a private  
method and a private static inner class into a class called PipedUtils
Can my addition be added?  Is JDK 1.5 a concern?

~ David Smiley
    MITRE

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message