@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class TeeOutputStream extends java.io.OutputStream
OutputStream
implementation that can cause
everything provided to it to be written to multiple output streams (e.g.,
to both a file and to standard output, or to both a file and a network
socket). Any number of destination streams (including zero, if desired) may
be specified.Constructor and Description |
---|
TeeOutputStream(java.util.Collection<? extends java.io.OutputStream> targetStreams)
Creates a new instance of this output stream that will write any data
received to each of the provided target streams.
|
TeeOutputStream(java.io.OutputStream... targetStreams)
Creates a new instance of this output stream that will write any data
received to each of the provided target streams.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes each of the target output streams.
|
void |
flush()
Flushes each of the target output streams to force any buffered content to
be written out.
|
void |
write(byte[] b)
Writes the entire contents of the provided byte array to each of the target
output streams.
|
void |
write(byte[] b,
int off,
int len)
Writes a portion of the contents of the provided byte array to each of the
target output streams.
|
void |
write(int b)
Writes the provided byte of data to each of the target output streams.
|
public TeeOutputStream(@Nullable java.io.OutputStream... targetStreams)
targetStreams
- The set of output streams to which any data received
will be written. If it is null
or empty,
then any data received will simply be discarded.public TeeOutputStream(@Nullable java.util.Collection<? extends java.io.OutputStream> targetStreams)
targetStreams
- The set of output streams to which any data received
will be written. If it is null
or empty,
then any data received will simply be discarded.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte of data to be written. Only the lower eight bits
of the provided value will be written.java.io.IOException
- If a problem occurs while writing the provided byte
to any of the target output streams.public void write(@NotNull byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte array containing the data to be written.java.io.IOException
- If a problem occurs while writing the provided data
to any of the target output streams.public void write(@NotNull byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte array containing the data to be written.off
- The offset within the array at which the data should start
being written.len
- The number of bytes from the array that should be written.java.io.IOException
- If a problem occurs while writing the provided data
to any of the target output streams.public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
- If a problem occurs while flushing any of the target
output streams.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
- If a problem occurs while closing any of the target
output streams. Note that even if an exception is
thrown, an attempt will be made to close all target
streams. If multiple target streams throw an
exception, then the first exception encountered will
be thrown.