Class TeeOutputStream

java.lang.Object
java.io.OutputStream
com.randomnoun.common.io.TeeOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class TeeOutputStream extends OutputStream
An outputstream which mimics the 'tee' unix utility. It writes to two outputStreams at the same time
  • Field Details

  • Constructor Details

  • Method Details

    • write

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

      public void write(byte[] b, int off, int len) throws IOException
      Writes the specified bytes to both streams.
      Overrides:
      write in class OutputStream
      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.
    • write

      public void write(int b) throws IOException
      Writes a byte to both streams.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to write
      Throws:
      IOException - if an I/O error occurs.
    • flush

      public void flush() throws IOException
      Flushes both streams.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      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 OutputStream
      Throws:
      IOException - if an I/O error occurs.