Package org.apache.commons.io.input
Class TeeInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.TeeInputStream
- All Implemented Interfaces:
- Closeable,- AutoCloseable
InputStream proxy that transparently writes a copy of all bytes read
 from the proxied stream to a given OutputStream. Using 
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. You may configure whether the input stream closes the
 output stream.
 
- Since:
- 1.4
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.commons.io.input.ProxyInputStreamProxyInputStream.AbstractBuilder<T,B extends AbstractStreamBuilder<T, B>> 
- 
Field SummaryFields inherited from class java.io.FilterInputStreamin
- 
Constructor SummaryConstructorsConstructorDescriptionTeeInputStream(InputStream input, OutputStream branch) Constructs a TeeInputStream that proxies the givenInputStreamand copies all read bytes to the givenOutputStream.TeeInputStream(InputStream input, OutputStream branch, boolean closeBranch) Constructs a TeeInputStream that proxies the givenInputStreamand copies all read bytes to the givenOutputStream.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes the proxied input stream and, if so configured, the associated output stream.intread()Reads a single byte from the proxied input stream and writes it to the associated output stream.intread(byte[] bts) Reads bytes from the proxied input stream and writes the read bytes to the associated output stream.intread(byte[] bts, int st, int end) Reads bytes from the proxied input stream and writes the read bytes to the associated output stream.Methods inherited from class org.apache.commons.io.input.ProxyInputStreamafterRead, available, beforeRead, handleIOException, mark, markSupported, reset, setReference, skip, unwrap
- 
Constructor Details- 
TeeInputStreamConstructs a TeeInputStream that proxies the givenInputStreamand copies all read bytes to the givenOutputStream. The given output stream will not be closed when this stream gets closed.- Parameters:
- input- input stream to be proxied
- branch- output stream that will receive a copy of all bytes read
 
- 
TeeInputStreamConstructs a TeeInputStream that proxies the givenInputStreamand copies all read bytes to the givenOutputStream. The given output stream will be closed when this stream gets closed if the closeBranch parameter istrue.- Parameters:
- input- input stream to be proxied
- branch- output stream that will receive a copy of all bytes read
- closeBranch- flag for closing also the output stream when this stream is closed
 
 
- 
- 
Method Details- 
closeCloses 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.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- ProxyInputStream
- Throws:
- IOException- if either of the streams could not be closed
 
- 
readReads a single byte from the proxied input stream and writes it to the associated output stream.- Overrides:
- readin class- ProxyInputStream
- Returns:
- next byte from the stream, or -1 if the stream has ended
- Throws:
- IOException- if the stream could not be read (or written)
 
- 
readReads bytes from the proxied input stream and writes the read bytes to the associated output stream.- Overrides:
- readin class- ProxyInputStream
- Parameters:
- bts- byte buffer
- Returns:
- number of bytes read, or -1 if the stream has ended
- Throws:
- IOException- if the stream could not be read (or written)
 
- 
readReads bytes from the proxied input stream and writes the read bytes to the associated output stream.- Overrides:
- readin class- ProxyInputStream
- Parameters:
- bts- byte buffer
- st- start offset within the buffer
- end- maximum number of bytes to read
- Returns:
- number of bytes read, or -1 if the stream has ended
- Throws:
- IOException- if the stream could not be read (or written)
 
 
-