Package com.randomnoun.common.io
Class TeeOutputStream
java.lang.Object
java.io.OutputStream
com.randomnoun.common.io.TeeOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
An outputstream which mimics the 'tee' unix utility.
It writes to two outputStreams at the same time
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OutputStream
The second OutputStream to write to.protected OutputStream
The OutputStream -
Constructor Summary
ConstructorsConstructorDescriptionTeeOutputStream
(OutputStream out, OutputStream branch) Constructs a TeeOutputStream. -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
out
The OutputStream -
branch
The second OutputStream to write to.
-
-
Constructor Details
-
TeeOutputStream
Constructs a TeeOutputStream.- Parameters:
out
- the main OutputStreambranch
- the second OutputStream
-
-
Method Details
-
write
Writes the bytes to both streams.- Overrides:
write
in classOutputStream
- Parameters:
b
- the bytes to write- Throws:
IOException
- if an I/O error occurs.
-
write
Writes the specified bytes to both streams.- Overrides:
write
in classOutputStream
- Parameters:
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to write- Throws:
IOException
- if an I/O error occurs.
-
write
Writes a byte to both streams.- Specified by:
write
in classOutputStream
- Parameters:
b
- the byte to write- Throws:
IOException
- if an I/O error occurs.
-
flush
Flushes both streams.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if an I/O error occurs.
-
close
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 classOutputStream
- Throws:
IOException
- if an I/O error occurs.
-