Package org.apache.commons.io.input

# Class ClosedReader

java.lang.Object
java.io.Reader
org.apache.commons.io.input.ClosedReader

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `Readable`

public class ClosedReader extends 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

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ClosedReader`
  `CLOSED_READER`
  Deprecated.
  `INSTANCE`.
  `static final ClosedReader`
  `INSTANCE`
  The singleton instance.

  ### Fields inherited from class java.io.Reader

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClosedReader()`
  Construct a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `int`
  `read(char[] cbuf, int off, int len)`
  A no-op read method that always indicates end-of-stream.

  ### Methods inherited from class java.io.Reader

  `mark, markSupported, read, read, read, ready, reset, skip`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### INSTANCE

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

  - ### CLOSED_READER

    @Deprecated public static final ClosedReader CLOSED_READER
    Deprecated.
    `INSTANCE`.
    The singleton instance.

- ## Constructor Details

  - ### ClosedReader

    public ClosedReader()
    Construct a new instance.

- ## Method Details

  - ### close

    public void close() throws IOException
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Specified by:
      `close` in class `Reader`
    Throws:
      `IOException`

  - ### read

    public int read(char[] cbuf, int off, int len)
    A no-op read method that always indicates end-of-stream.

    Behavior:

    - If `len == 0`, returns `0` immediately (no characters are read).
    - Otherwise, always returns -1 to signal that the stream is closed or at end-of-stream.
    Specified by:
      `read` in class `Reader`
    Parameters:
      `cbuf` - The destination buffer.
      `off` - The offset at which to start storing characters.
      `len` - The maximum number of characters to read.
    Returns:
      `0` if `len == 0`; otherwise always -1.
    Throws:
      `IndexOutOfBoundsException` - If `off < 0`, `len < 0`, or `off + len > cbuf.length`.