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 anOutputStreamimplementation 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 voidclose()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.
-
-
-
Constructor Detail
-
TeeOutputStream
public TeeOutputStream(@Nullable 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 isnullor empty, then any data received will simply be discarded.
-
TeeOutputStream
public TeeOutputStream(@Nullable 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 isnullor 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:
writein 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(@NotNull byte[] b) throws java.io.IOException
Writes the entire contents of the provided byte array to each of the target output streams.- Overrides:
writein 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(@NotNull 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:
writein 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:
flushin interfacejava.io.Flushable- Overrides:
flushin 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein 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.
-
-