Class ClosedReader

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

    public class ClosedReader
    extends java.io.Reader
    Always returns IOUtils.EOF to all attempts to read something from it.

    Typically uses of this class include testing for corner cases in methods that accept readers and acting as a sentinel value instead of a null reader.

    Since:
    2.7
    • Constructor Summary

      Constructors 
      Constructor Description
      ClosedReader()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      int read​(char[] cbuf, int off, int len)
      Returns -1 to indicate that the stream is closed.
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • INSTANCE

        public static final ClosedReader INSTANCE
        The singleton instance.
        Since:
        2.12.0
      • CLOSED_READER

        @Deprecated
        public static final ClosedReader CLOSED_READER
        Deprecated.
        The singleton instance.
    • Constructor Detail

      • ClosedReader

        public ClosedReader()
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        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
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
        Returns -1 to indicate that the stream is closed.
        Specified by:
        read in class java.io.Reader
        Parameters:
        cbuf - ignored
        off - ignored
        len - ignored
        Returns:
        always -1