public class TeeInputStream extends ProxyInputStream
ProxyInputStream.skip(long)
or ProxyInputStream.mark(int)
/ProxyInputStream.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.
ObservableInputStream
in
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
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.
|
afterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skip
public TeeInputStream(InputStream input, OutputStream branch)
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 readpublic TeeInputStream(InputStream input, OutputStream branch, boolean closeBranch)
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 closedpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class ProxyInputStream
IOException
- if either of the streams could not be closedpublic int read() throws IOException
read
in class ProxyInputStream
IOException
- if the stream could not be read (or written)public int read(byte[] bts, int st, int end) throws IOException
read
in class ProxyInputStream
bts
- byte bufferst
- start offset within the bufferend
- maximum number of bytes to readIOException
- if the stream could not be read (or written)public int read(byte[] bts) throws IOException
read
in class ProxyInputStream
bts
- byte bufferIOException
- if the stream could not be read (or written)Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.