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 Details

    • INSTANCE

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

      private final Supplier<IOException> exceptionSupplier
      A supplier for the exception that is thrown by all methods of this class.
  • Constructor Details

    • BrokenOutputStream

      public BrokenOutputStream()
      Creates a new stream that always throws an IOException.
    • BrokenOutputStream

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

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