Class ClosedInputStream

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

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

    Since:
    1.4
    • Constructor Summary

      Constructors 
      Constructor Description
      ClosedInputStream()
      Constructs a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

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

      • read

        public int read()
        Returns -1 to indicate that the stream is closed.
        Specified by:
        read in class java.io.InputStream
        Returns:
        always -1.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Returns -1 to indicate that the stream is closed.
        Overrides:
        read in class java.io.InputStream
        Parameters:
        b - The buffer to read bytes into.
        off - The start offset.
        len - The number of bytes to read.
        Returns:
        If len is zero, then 0; otherwise -1.
        Throws:
        java.lang.NullPointerException - if the byte array is null.
        java.lang.IndexOutOfBoundsException - if off or len are negative, or if off + len is greater than b.length.
        java.io.IOException