TeeOutputStream (Commons IO 2.5)
Date: 2016-12-01

org.apache.commons.io.output

## Class TeeOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - org.apache.commons.io.output.ProxyOutputStream
      - - org.apache.commons.io.output.TeeOutputStream

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

      public class TeeOutputStream
      extends ProxyOutputStream

  Classic splitter of OutputStream. Named after the unix 'tee' command. It allows a stream to be branched off so there are now two streams.
  Version:
    $Id: TeeOutputStream.java 1686503 2015-06-19 21:32:13Z sebb $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.io.OutputStream` | `branch` the second OutputStream to write to

    - ### Fields inherited from class java.io.FilterOutputStream

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TeeOutputStream(java.io.OutputStream out, java.io.OutputStream branch)` Constructs a TeeOutputStream.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes both output streams.
    `void` | `flush()` Flushes both streams.
    `void` | `write(byte[] b)` Write the bytes to both streams.
    `void` | `write(byte[] b, int off, int len)` Write the specified bytes to both streams.
    `void` | `write(int b)` Write a byte to both streams.

    - ### Methods inherited from class org.apache.commons.io.output.ProxyOutputStream

      `afterWrite, beforeWrite, handleIOException`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### branch

          protected java.io.OutputStream branch

      the second OutputStream to write to

  - ### Constructor Detail

    - #### TeeOutputStream

          public TeeOutputStream(java.io.OutputStream out,
                         java.io.OutputStream branch)

      Constructs a TeeOutputStream.
      Parameters:
        `out` - the main OutputStream
        `branch` - the second OutputStream

  - ### Method Detail

    - #### write

          public void write(byte[] b)
                     throws java.io.IOException

      Write the bytes to both streams.
      Overrides:
        `write` in class `ProxyOutputStream`
      Parameters:
        `b` - the bytes to write
      Throws:
        `java.io.IOException` - if an I/O error occurs

    - #### write

          public void write(byte[] b,
                   int off,
                   int len)
                     throws java.io.IOException

      Write the specified bytes to both streams.
      Overrides:
        `write` in class `ProxyOutputStream`
      Parameters:
        `b` - the bytes to write
        `off` - The start offset
        `len` - The number of bytes to write
      Throws:
        `java.io.IOException` - if an I/O error occurs

    - #### write

          public void write(int b)
                     throws java.io.IOException

      Write a byte to both streams.
      Overrides:
        `write` in class `ProxyOutputStream`
      Parameters:
        `b` - the byte to write
      Throws:
        `java.io.IOException` - if an I/O error occurs

    - #### flush

          public void flush()
                     throws java.io.IOException

      Flushes both streams.
      Specified by:
        `flush` in interface `java.io.Flushable`
      Overrides:
        `flush` in class `ProxyOutputStream`
      Throws:
        `java.io.IOException` - if an I/O error occurs

    - #### close

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

Copyright (c) 2002-2016 Apache Software Foundation