org.apache.commons.io.output

## Class BrokenOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.commons.io.output.BrokenOutputStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

      public class BrokenOutputStream
      extends OutputStream

  Always throws an exception from all `OutputStream` methods where `IOException` is declared.

  This class is mostly useful for testing error handling.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static BrokenOutputStream` | `INSTANCE` The singleton instance using a default IOException.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BrokenOutputStream()` Constructs a new stream that always throws an `IOException`.
    `BrokenOutputStream(java.util.function.Function<String,Throwable> exceptionFunction)` Constructs a new stream that always throws the supplied exception.
    `BrokenOutputStream(Throwable exception)` Constructs a new stream that always throws the given exception.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Throws the configured exception.
    `void` | `flush()` Throws the configured exception.
    `void` | `write(int b)` Throws the configured exception.

    - ### Methods inherited from class java.io.OutputStream

      `write, write`

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

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

- - ### Field Detail

    - #### INSTANCE

          public static final BrokenOutputStream INSTANCE

      The singleton instance using a default IOException.

  - ### Constructor Detail

    - #### BrokenOutputStream

          public BrokenOutputStream()

      Constructs a new stream that always throws an `IOException`.

    - #### BrokenOutputStream

          public BrokenOutputStream(java.util.function.Function<String,Throwable> exceptionFunction)

      Constructs a new stream that always throws the supplied exception.

      This class uses the invoked method name as the function input.

      Parameters:
        `exceptionFunction` - a supplier for the IOException or RuntimeException to be thrown.

    - #### BrokenOutputStream

          public BrokenOutputStream(Throwable exception)

      Constructs a new stream that always throws the given exception.
      Parameters:
        `exception` - the exception to be thrown.

  - ### Method Detail

    - #### close

          public void close()
                     throws IOException

      Throws the configured exception.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `OutputStream`
      Throws:
        `IOException` - always throws the exception configured in a constructor.

    - #### flush

          public void flush()
                     throws IOException

      Throws the configured exception.
      Specified by:
        `flush` in interface `Flushable`
      Overrides:
        `flush` in class `OutputStream`
      Throws:
        `IOException` - always throws the exception configured in a constructor.

    - #### write

          public void write(int b)
                     throws IOException

      Throws the configured exception.
      Specified by:
        `write` in class `OutputStream`
      Parameters:
        `b` - ignored.
      Throws:
        `IOException` - always throws the exception configured in a constructor.