Class TeeOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
    public class TeeOutputStream
    extends FilterOutputStream
    Classic splitter of OutputStream. Named after the Unix 'tee' command. It allows a stream to be branched off so there are now two streams.
    • Field Detail

      • branch

        protected OutputStream branch
        The second OutputStream to write to.

        TODO Make private and final in 3.0.

    • Constructor Detail

      • TeeOutputStream

        public TeeOutputStream​(OutputStream out,
                               OutputStream branch)
        Constructs a TeeOutputStream.
        Parameters:
        out - the main OutputStream
        branch - the second OutputStream
    • Method Detail

      • write

        public void write​(@NonNull
                          byte[] b)
                   throws IOException
        Writes the bytes to both streams.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        b - the bytes to write
        Throws:
        IOException - if an I/O error occurs.
      • write

        public void write​(@NonNull
                          byte[] b,
                          int off,
                          int len)
                   throws IOException
        Writes the specified bytes to both streams.
        Overrides:
        write in class FilterOutputStream
        Parameters:
        b - the bytes to write
        off - The start offset
        len - The number of bytes to write
        Throws:
        IOException - if an I/O error occurs.
      • close

        public void close()
                   throws IOException
        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 interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class FilterOutputStream
        Throws:
        IOException - if an I/O error occurs.