|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.gc.iotools.stream.base.AbstractInputStreamWrapper
com.gc.iotools.stream.is.TeeInputStreamOutputStream
public class TeeInputStreamOutputStream
Copies the data from the underlying InputStream to the
OutputStream passed in the constructor. The data copied are
similar to the underlying InputStream.
When the method is invoked all the bytes
remaining in the underlying AbstractInputStreamWrapper.close()InputStream are copied to the
OutputStream. This behavior is different from this class and
TeeInputStream in Apache commons-io.
Bytes skipped are copied to the OutputStream.
Sample usage:
InputStream source=... //some data to be readed.
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[] bytes=destination1.getBytes();
TeeInputStream| Field Summary | |
|---|---|
protected boolean |
closeStreams
If true source and destination
streams are closed when AbstractInputStreamWrapper.close() is invoked. |
protected OutputStream |
destination
|
| Fields inherited from class com.gc.iotools.stream.base.AbstractInputStreamWrapper |
|---|
closeCalled, source |
| Constructor Summary | |
|---|---|
TeeInputStreamOutputStream(InputStream source,
OutputStream destination)
Creates a TeeInputStreamOutputStream and saves its argument,
the input stream source and the OutputStream
destination for later use. |
|
TeeInputStreamOutputStream(InputStream source,
OutputStream destination,
boolean closeStreams)
Creates a TeeInputStreamOutputStream and saves its argument,
the input stream source and the output stream
destination for later use. |
|
| Method Summary | |
|---|---|
int |
available()
|
void |
closeOnce()
This method is called when the method AbstractInputStreamWrapper.close() is invoked. |
int |
innerRead(byte[] b,
int off,
int len)
|
void |
mark(int readLimit)
Marks the current position in this input stream. |
boolean |
markSupported()
|
int |
read()
|
void |
reset()
Repositions this stream to the position at the time the mark
method was last called on this input stream. |
| Methods inherited from class com.gc.iotools.stream.base.AbstractInputStreamWrapper |
|---|
close, read, skip |
| Methods inherited from class java.io.InputStream |
|---|
read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final OutputStream destination
protected final boolean closeStreams
true source and destination
streams are closed when AbstractInputStreamWrapper.close() is invoked.
| Constructor Detail |
|---|
public TeeInputStreamOutputStream(InputStream source,
OutputStream destination)
Creates a TeeInputStreamOutputStream and saves its argument,
the input stream source and the OutputStream
destination for later use.
When the method AbstractInputStreamWrapper.close() it is invoked the remaining content of
the source stream is copied to the destination
and the source and destination streams are
closed.
source - The underlying InputStreamdestination - Data read from source are also written to this
OutputStream.
public TeeInputStreamOutputStream(InputStream source,
OutputStream destination,
boolean closeStreams)
TeeInputStreamOutputStream and saves its argument,
the input stream source and the output stream
destination for later use.
source - The underlying InputStreamdestination - Data read from source are also written to this
OutputStream.closeStreams - if true the destination will be
closed when the AbstractInputStreamWrapper.close() method is invoked. If
false the close method on the underlying streams
will not be called (it must be invoked externally).| Method Detail |
|---|
public int available()
throws IOException
available in class InputStreamIOException
public void closeOnce()
throws IOException
This method is called when the method AbstractInputStreamWrapper.close() is invoked. It
copies all the data eventually remaining in the source
InputStream passed in the constructor to the destination
OutputStream.
The standard behavior is to close both the underlying
InputStream and OutputStream. When the class
was constructed with the parameter
closeStreams set to false
the underlying streams must be closed externally.
closeOnce in class AbstractInputStreamWrapperIOException - thrown when a IO problem occurs in reading or writing the
data.AbstractInputStreamWrapper.close()
public int innerRead(byte[] b,
int off,
int len)
throws IOException
innerRead in class AbstractInputStreamWrapperIOExceptionpublic void mark(int readLimit)
Marks the current position in this input stream. A subsequent call to the
reset method repositions this stream at the last marked
position so that subsequent reads re-read the same bytes.
mark in class InputStreamreadLimit - the maximum limit of bytes that can be read before the mark
position becomes invalid.reset(),
InputStream.mark(int)public boolean markSupported()
markSupported in class InputStream
public int read()
throws IOException
read in class AbstractInputStreamWrapperIOException
public void reset()
throws IOException
Repositions this stream to the position at the time the mark
method was last called on this input stream.
After reset method is called the data is not copied anymore
to the destination OutputStream until the position where
reset was issued is reached again. This ensures the data
copied to the destination OutputStream reflects the data contained in the
source InputStream (the one passed in the constructor).
reset in class InputStreamIOException - If the source stream has an exception in calling reset().#mark(),
InputStream.reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||