Package 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
Broken output stream. This stream always throws an `IOException` from all `OutputStream` methods.

This class is mostly useful for testing error handling in code that uses an output stream.

Since:
  2.0

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final BrokenOutputStream`
  `INSTANCE`
  A singleton instance.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BrokenOutputStream()`
  Constructs a new stream that always throws an `IOException`.
  `BrokenOutputStream(IOException exception)`
  Constructs a new stream that always throws the given exception.
  `BrokenOutputStream(Supplier<IOException> exceptionSupplier)`
  Constructs a new stream that always throws an `IOException`.

- ## Method Summary

  Modifier and Type
  Method
  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 Details

  - ### INSTANCE

    public static final BrokenOutputStream INSTANCE
    A singleton instance.
    Since:
      2.12.0

- ## Constructor Details

  - ### BrokenOutputStream

    public BrokenOutputStream()
    Constructs a new stream that always throws an `IOException`.

  - ### BrokenOutputStream

    public BrokenOutputStream(IOException exception)
    Constructs a new stream that always throws the given exception.
    Parameters:
      `exception` - the exception to be thrown.

  - ### BrokenOutputStream

    public BrokenOutputStream(Supplier<IOException> exceptionSupplier)
    Constructs a new stream that always throws an `IOException`.
    Parameters:
      `exceptionSupplier` - a supplier for the exception to be thrown.
    Since:
      2.12.0

- ## Method Details

  - ### close

    public void close() throws IOException
    Throws the configured exception.
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `OutputStream`
    Throws:
      `IOException` - always thrown

  - ### flush

    public void flush() throws IOException
    Throws the configured exception.
    Specified by:
      `flush` in interface `Flushable`
    Overrides:
      `flush` in class `OutputStream`
    Throws:
      `IOException` - always thrown

  - ### write

    public void write(int b) throws IOException
    Throws the configured exception.
    Specified by:
      `write` in class `OutputStream`
    Parameters:
      `b` - ignored
    Throws:
      `IOException` - always thrown