Package com.unboundid.util
Class TeeOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.unboundid.util.TeeOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class TeeOutputStream extends java.io.OutputStream
This class provides anOutputStream
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 Summary
Constructors Constructor Description 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.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
TeeOutputStream
public 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.- Parameters:
targetStreams
- The set of output streams to which any data received will be written. If it isnull
or empty, then any data received will simply be discarded.
-
TeeOutputStream
public 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.- Parameters:
targetStreams
- The set of output streams to which any data received will be written. If it isnull
or empty, then any data received will simply be discarded.
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
Writes the provided byte of data to each of the target output streams.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
b
- The byte of data to be written. Only the lower eight bits of the provided value will be written.- Throws:
java.io.IOException
- If a problem occurs while writing the provided byte to any of the target output streams.
-
write
public void write(byte[] b) throws java.io.IOException
Writes the entire contents of the provided byte array to each of the target output streams.- Overrides:
write
in classjava.io.OutputStream
- Parameters:
b
- The byte array containing the data to be written.- Throws:
java.io.IOException
- If a problem occurs while writing the provided data to any of the target output streams.
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
Writes a portion of the contents of the provided byte array to each of the target output streams.- Overrides:
write
in classjava.io.OutputStream
- Parameters:
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.- Throws:
java.io.IOException
- If a problem occurs while writing the provided data to any of the target output streams.
-
flush
public void flush() throws java.io.IOException
Flushes each of the target output streams to force any buffered content to be written out.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
- If a problem occurs while flushing any of the target output streams.
-
close
public void close() throws java.io.IOException
Closes each of the target output streams.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
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.
-
-