Class BrokenWriter

java.lang.Object
java.io.Writer
org.apache.commons.io.output.BrokenWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class BrokenWriter extends Writer
Always throws an IOException from all Writer methods.

This class is mostly useful for testing error handling in code that uses a writer.

Since:
2.0
  • Field Details

    • INSTANCE

      public static final BrokenWriter INSTANCE
      The 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

    • BrokenWriter

      public BrokenWriter()
      Creates a new writer that always throws an IOException.
    • BrokenWriter

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

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