Class BrokenInputStream

java.lang.Object
java.io.InputStream
org.apache.commons.io.input.BrokenInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class BrokenInputStream extends InputStream
Always throws an IOException from all the InputStream methods where the exception is declared.

This class is mostly useful for testing error handling.

Since:
2.0
  • Field Details

    • INSTANCE

      public static final BrokenInputStream 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

    • BrokenInputStream

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

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

      public BrokenInputStream(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