Package org.apache.commons.io.input
Class ClosedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.ClosedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ClosedInputStream extends java.io.InputStreamAlways returnsIOUtils.EOFto 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
nullinput stream.- Since:
- 1.4
-
-
Field Summary
Fields Modifier and Type Field Description static ClosedInputStreamCLOSED_INPUT_STREAMDeprecated.UseINSTANCE.static ClosedInputStreamINSTANCEThe singleton instance.
-
Constructor Summary
Constructors Constructor Description ClosedInputStream()Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static java.io.InputStreamifNull(java.io.InputStream in)ReturnsINSTANCEif the given InputStream is null, otherwise returns the given input stream.intread()Returns-1to indicate that the stream is closed.intread(byte[] b, int off, int len)Returns-1to indicate that the stream is closed.
-
-
-
Field Detail
-
INSTANCE
public static final ClosedInputStream INSTANCE
The singleton instance.- Since:
- 2.12.0
-
CLOSED_INPUT_STREAM
@Deprecated public static final ClosedInputStream CLOSED_INPUT_STREAM
Deprecated.UseINSTANCE.The singleton instance.
-
-
Method Detail
-
ifNull
static java.io.InputStream ifNull(java.io.InputStream in)
ReturnsINSTANCEif the given InputStream is null, otherwise returns the given input stream.- Parameters:
in- the InputStream to test.- Returns:
INSTANCEif the given InputStream is null, otherwise returns the given input stream.
-
read
public int read()
Returns-1to indicate that the stream is closed.- Specified by:
readin classjava.io.InputStream- Returns:
- always
-1.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReturns-1to indicate that the stream is closed.- Overrides:
readin classjava.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 isnull.java.lang.IndexOutOfBoundsException- ifofforlenare negative, or ifoff + lenis greater thanb.length.java.io.IOException
-
-