Package com.unboundid.util
Class TeeOutputStream
java.lang.Object
java.io.OutputStream
com.unboundid.util.TeeOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
This class provides an
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 Summary
ConstructorsConstructorDescriptionTeeOutputStream(OutputStream... targetStreams) Creates a new instance of this output stream that will write any data received to each of the provided target streams.TeeOutputStream(Collection<? extends 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
Modifier and TypeMethodDescriptionvoidclose()Closes each of the target output streams.voidflush()Flushes each of the target output streams to force any buffered content to be written out.voidwrite(byte[] b) Writes the entire contents of the provided byte array to each of the target output streams.voidwrite(byte[] b, int off, int len) Writes a portion of the contents of the provided byte array to each of the target output streams.voidwrite(int b) Writes the provided byte of data to each of the target output streams.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
TeeOutputStream
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 isnullor empty, then any data received will simply be discarded.
-
TeeOutputStream
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 isnullor empty, then any data received will simply be discarded.
-
-
Method Details
-
write
Writes the provided byte of data to each of the target output streams.- Specified by:
writein classOutputStream- Parameters:
b- The byte of data to be written. Only the lower eight bits of the provided value will be written.- Throws:
IOException- If a problem occurs while writing the provided byte to any of the target output streams.
-
write
Writes the entire contents of the provided byte array to each of the target output streams.- Overrides:
writein classOutputStream- Parameters:
b- The byte array containing the data to be written.- Throws:
IOException- If a problem occurs while writing the provided data to any of the target output streams.
-
write
Writes a portion of the contents of the provided byte array to each of the target output streams.- Overrides:
writein classOutputStream- 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:
IOException- If a problem occurs while writing the provided data to any of the target output streams.
-
flush
Flushes each of the target output streams to force any buffered content to be written out.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- If a problem occurs while flushing any of the target output streams.
-
close
Closes each of the target output streams.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
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.
-