Package org.apache.commons.io.output
Class TeeOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.commons.io.output.ProxyOutputStream
-
- org.apache.commons.io.output.TeeOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class TeeOutputStream extends ProxyOutputStream
Classic splitter ofOutputStream
. Named after the Unix 'tee' command. It allows a stream to be branched off so there are now two streams.
-
-
Constructor Summary
Constructors Constructor Description TeeOutputStream(OutputStream out, OutputStream branch)
Constructs a TeeOutputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes both output streams.void
flush()
Flushes both streams.void
write(byte[] b)
Write the bytes to both streams.void
write(byte[] b, int off, int len)
Write the specified bytes to both streams.void
write(int b)
Write a byte to both streams.-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
TeeOutputStream
public TeeOutputStream(OutputStream out, OutputStream branch)
Constructs a TeeOutputStream.- Parameters:
out
- the main OutputStreambranch
- the second OutputStream
-
-
Method Detail
-
write
public void write(byte[] b) throws IOException
Write the bytes to both streams.- Overrides:
write
in classProxyOutputStream
- Parameters:
b
- the bytes to write- Throws:
IOException
- if an I/O error occurs
-
write
public void write(byte[] b, int off, int len) throws IOException
Write the specified bytes to both streams.- Overrides:
write
in classProxyOutputStream
- Parameters:
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to write- Throws:
IOException
- if an I/O error occurs
-
write
public void write(int b) throws IOException
Write a byte to both streams.- Overrides:
write
in classProxyOutputStream
- Parameters:
b
- the byte to write- Throws:
IOException
- if an I/O error occurs
-
flush
public void flush() throws IOException
Flushes both streams.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classProxyOutputStream
- Throws:
IOException
- if an I/O error occurs
-
close
public void close() throws IOException
Closes both output streams. If closing the main output stream throws an exception, attempt to close the branch output stream. If closing the main and branch output streams both throw exceptions, which exceptions is thrown by this method is currently unspecified and subject to change.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classProxyOutputStream
- Throws:
IOException
- if an I/O error occurs
-
-