These classes allow the user to connect streams in different ways.
This class is an InputStream wrapper: its constructor takes an InputStream one or more OutputStream. The data you can read from it is the same as the original InputStream, but while data is being read from the source it is also copied to the OutputStream.
Sample usage:
InputStream source=... //some data to be read. ByteArrayOutputStream destination1= new ByteArrayOutputStream(); ByteArrayOutputStream destination2= new ByteArrayOutputStream(); TeeInputStreamOutputStream tee=new TeeInputStreamOutputStream(source,destination1); org.apache.commons.io.IOUtils.copy(tee,destination2); tee.close(); //at this point both destination1 and destination2 contains the same bytes. byte[] bytes1=destination1.getBytes(); byte[] bytes2=destination2.getBytes();
In case of usage of mark() and reset() methods the data copied are similar to the underlying InputStream.
For further information see the api javadoc
The class TeeInputStreamOutputStream has a counterpart for Character oriented I/O in TeeReaderWriter. The usage and the purpose are identical.
For further information see the api javadoc
This class is an OutputStream wrapper: its constructor takes two or more OutputStream.
It copies the data that is written to this class to the array of OutputStream passed in the constructor, allowing to write to multiple OutputStream at once. It also collect statistics on the operations done (time spent writing to the internal streams, amount of data written).
Usage:
InputStream source=... //some data to be read (as an example). ByteArrayOutputStream destination1= new ByteArrayOutputStream(); ByteArrayOutputStream destination2= new ByteArrayOutputStream(); TeeOutputStream tee = new TeeOutputStream(destination1, destination2); org.apache.commons.io.IOUtils.copy(source, tee); tee.close(); //at this point both destination1 and destination2 contains the same bytes.
For further information see the api javadoc
The class TeeOutputStream has a counterpart for Character oriented I/O in TeeWriter. The usage and the purpose are identical.
For further information see the api javadoc