org.apache.commons.io.input
Class TeeInputStream
public class TeeInputStream
InputStream proxy that transparently writes a copy of all bytes read
from the proxied stream to a given OutputStream. Using
skip(long)
or
mark(int)
/
reset()
on the stream will result on some
bytes from the input stream being skipped or duplicated in the output
stream.
The proxied input stream is closed when the
close()
method is
called on this proxy. It is configurable whether the associated output
stream will also closed.
$Id: TeeInputStream.java 587913 2007-10-24 15:47:30Z niallp $private OutputStream | branch - The output stream that will receive a copy of all bytes read from the
proxied input stream.
|
private boolean | closeBranch - Flag for closing also the associated output stream when this
stream is closed.
|
TeeInputStream(InputStream input, OutputStream branch) - Creates a TeeInputStream that proxies the given
InputStream
and copies all read bytes to the given OutputStream .
|
TeeInputStream(InputStream input, OutputStream branch, boolean closeBranch) - Creates a TeeInputStream that proxies the given
InputStream
and copies all read bytes to the given OutputStream .
|
void | close() - Closes the proxied input stream and, if so configured, the associated
output stream.
|
int | read() - Reads a single byte from the proxied input stream and writes it to
the associated output stream.
|
int | read(byte[] bts) - Reads bytes from the proxied input stream and writes the read bytes
to the associated output stream.
|
int | read(byte[] bts, int st, int end) - Reads bytes from the proxied input stream and writes the read bytes
to the associated output stream.
|
branch
private final OutputStream branch
The output stream that will receive a copy of all bytes read from the
proxied input stream.
closeBranch
private final boolean closeBranch
Flag for closing also the associated output stream when this
stream is closed.
TeeInputStream
public TeeInputStream(InputStream input,
OutputStream branch)
Creates a TeeInputStream that proxies the given InputStream
and copies all read bytes to the given OutputStream
. The given
output stream will not be closed when this stream gets closed.
input
- input stream to be proxiedbranch
- output stream that will receive a copy of all bytes read
TeeInputStream
public TeeInputStream(InputStream input,
OutputStream branch,
boolean closeBranch)
Creates a TeeInputStream that proxies the given InputStream
and copies all read bytes to the given OutputStream
. The given
output stream will be closed when this stream gets closed if the
closeBranch parameter is true
.
input
- input stream to be proxiedbranch
- output stream that will receive a copy of all bytes readcloseBranch
- flag for closing also the output stream when this
stream is closed
close
public void close()
throws IOException
Closes the proxied input stream and, if so configured, the associated
output stream. An exception thrown from one stream will not prevent
closing of the other stream.
- close in interface ProxyInputStream
read
public int read()
throws IOException
Reads a single byte from the proxied input stream and writes it to
the associated output stream.
- read in interface ProxyInputStream
- next byte from the stream, or -1 if the stream has ended
read
public int read(byte[] bts)
throws IOException
Reads bytes from the proxied input stream and writes the read bytes
to the associated output stream.
- read in interface ProxyInputStream
- number of bytes read, or -1 if the stream has ended
read
public int read(byte[] bts,
int st,
int end)
throws IOException
Reads bytes from the proxied input stream and writes the read bytes
to the associated output stream.
- read in interface ProxyInputStream
bts
- byte bufferst
- start offset within the bufferend
- maximum number of bytes to read
- number of bytes read, or -1 if the stream has ended
Copyright (c) 2002-2009 Apache Software Foundation