Class BrokenReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable

    public class BrokenReader
    extends Reader
    Broken reader. This reader always throws an IOException from all the Reader methods where the exception is declared.

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

    Since:
    2.7
    • Constructor Detail

      • BrokenReader

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

        public BrokenReader()
        Creates a new reader that always throws an IOException
    • Method Detail

      • 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 thrown
      • 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 thrown
      • ready

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

        public void mark​(int readAheadLimit)
                  throws IOException
        Throws the configured exception.
        Overrides:
        mark in class Reader
        Parameters:
        readAheadLimit - ignored
        Throws:
        IOException - always thrown