Class BrokenReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public class BrokenReader
    extends java.io.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 Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.Supplier<java.lang.Throwable> exceptionSupplier
      A supplier for the exception that is thrown by all methods of this class.
      static BrokenReader INSTANCE
      A singleton instance using a default IOException.
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      BrokenReader()
      Constructs a new reader that always throws an IOException.
      BrokenReader​(java.io.IOException exception)
      Deprecated.
      BrokenReader​(java.lang.Throwable exception)
      Constructs a new reader that always throws the given exception.
      BrokenReader​(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
      Constructs a new reader that always throws the supplied exception.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Throws the configured exception.
      void mark​(int readAheadLimit)
      Throws the configured exception.
      int read​(char[] cbuf, int off, int len)
      Throws the configured exception.
      boolean ready()
      Throws the configured exception.
      void reset()
      Throws the configured exception.
      private java.lang.RuntimeException rethrow()
      Throws the configured exception from its supplier.
      long skip​(long n)
      Throws the configured exception.
      • Methods inherited from class java.io.Reader

        markSupported, nullReader, read, read, read, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

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

        private final java.util.function.Supplier<java.lang.Throwable> exceptionSupplier
        A supplier for the exception that is thrown by all methods of this class.
    • Constructor Detail

      • BrokenReader

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

        @Deprecated
        public BrokenReader​(java.io.IOException exception)
        Deprecated.
        Constructs a new reader that always throws the given exception.
        Parameters:
        exception - the exception to be thrown.
      • BrokenReader

        public BrokenReader​(java.util.function.Supplier<java.lang.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​(java.lang.Throwable exception)
        Constructs a new reader that always throws the given exception.
        Parameters:
        exception - the exception to be thrown.
        Since:
        2.16.0
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Throws the configured exception.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException - always throws the exception configured in a constructor.
      • mark

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

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

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

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

        private java.lang.RuntimeException rethrow()
        Throws the configured exception from its supplier.
        Returns:
        Throws the configured exception from its supplier.
      • skip

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