org.apache.commons.io.input

## Class ClosedInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.commons.io.input.ClosedInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class ClosedInputStream
      extends InputStream

  Always returns `IOUtils.EOF` to all attempts to read something from an input stream.

  Typically uses of this class include testing for corner cases in methods that accept input streams and acting as a sentinel value instead of a `null` input stream.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ClosedInputStream` | `INSTANCE` The singleton instance.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClosedInputStream()` Constructs a new instance.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `(package private) static InputStream` | `ifNull(InputStream in)` Returns `INSTANCE` if the given InputStream is null, otherwise returns the given input stream.
    `int` | `read()` Returns `-1` to indicate that the stream is closed.
    `int` | `read(byte[] b, int off, int len)` Returns `-1` to indicate that the stream is closed.

    - ### Methods inherited from class java.io.InputStream

      `available, close, mark, markSupported, read, reset, skip`

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

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

- - ### Field Detail

    - #### INSTANCE

          public static final ClosedInputStream INSTANCE

      The singleton instance.

  - ### Constructor Detail

    - #### ClosedInputStream

          public ClosedInputStream()

      Constructs a new instance.

  - ### Method Detail

    - #### ifNull

          static InputStream ifNull(InputStream in)

      Returns `INSTANCE` if the given InputStream is null, otherwise returns the given input stream.
      Parameters:
        `in` - the InputStream to test.
      Returns:
        `INSTANCE` if the given InputStream is null, otherwise returns the given input stream.

    - #### read

          public int read()

      Returns `-1` to indicate that the stream is closed.
      Specified by:
        `read` in class `InputStream`
      Returns:
        always `-1`.

    - #### read

          public int read(byte[] b,
                          int off,
                          int len)
                   throws IOException

      Returns `-1` to indicate that the stream is closed.
      Overrides:
        `read` in class `InputStream`
      Parameters:
        `b` - ignored.
        `off` - ignored.
        `len` - ignored.
      Returns:
        always -1.
      Throws:
        `IOException`