Class BrokenReader

java.lang.Object
java.io.Reader
org.apache.commons.io.input.BrokenReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class BrokenReader extends Reader
Always throws an exception from all Reader methods where IOException is declared.

This class is mostly useful for testing error handling.

Since:
2.7
  • Field Details

    • INSTANCE

      public static final BrokenReader INSTANCE
      A singleton instance using a default IOException.
      Since:
      2.12.0
  • Constructor Details

    • BrokenReader

      public BrokenReader()
      Constructs a new reader that always throws an IOException.
    • BrokenReader

      Deprecated.
      Constructs a new reader that always throws the given exception.
      Parameters:
      exception - the exception to be thrown.
    • BrokenReader

      public BrokenReader(Supplier<Throwable> exceptionSupplier)
      Constructs a new reader that always throws the supplied exception.
      Parameters:
      exceptionSupplier - a supplier for the IOException or RuntimeException to be thrown.
      Since:
      2.12.0
    • BrokenReader

      public BrokenReader(Throwable exception)
      Constructs a new reader that always throws the given exception.
      Parameters:
      exception - the exception to be thrown.
      Since:
      2.16.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
      Specified by:
      close in class Reader
      Throws:
      IOException - always throws the exception configured in a constructor.
    • mark

      public void mark(int readAheadLimit) throws IOException
      Throws the configured exception.
      Overrides:
      mark in class Reader
      Parameters:
      readAheadLimit - ignored.
      Throws:
      IOException - always throws the exception configured in a constructor.
    • read

      public int read(char[] cbuf, int off, int len) throws IOException
      Throws the configured exception.
      Specified by:
      read in class Reader
      Parameters:
      cbuf - ignored.
      off - ignored.
      len - ignored.
      Returns:
      nothing.
      Throws:
      IOException - always throws the exception configured in a constructor.
    • ready

      public boolean ready() throws IOException
      Throws the configured exception.
      Overrides:
      ready in class Reader
      Returns:
      nothing.
      Throws:
      IOException - always throws the exception configured in a constructor.
    • reset

      public void reset() throws IOException
      Throws the configured exception.
      Overrides:
      reset in class Reader
      Throws:
      IOException - always throws the exception configured in a constructor.
    • skip

      public long skip(long n) throws IOException
      Throws the configured exception.
      Overrides:
      skip in class Reader
      Parameters:
      n - ignored.
      Returns:
      nothing.
      Throws:
      IOException - always throws the exception configured in a constructor.