Class ClosedReader
java.lang.Object
java.io.Reader
org.apache.commons.io.input.ClosedReader
- All Implemented Interfaces:
Closeable, AutoCloseable, Readable
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
FieldsModifier and TypeFieldDescriptionstatic final ClosedReaderDeprecated.static final ClosedReaderThe singleton instance. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
INSTANCE
-
CLOSED_READER
Deprecated.The singleton instance.
-
-
Constructor Details
-
ClosedReader
public ClosedReader()Construct a new instance.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classReader- Throws:
IOException
-
read
A no-op read method that always indicates end-of-stream.Behavior:
- If
len == 0, returns0immediately (no characters are read). - Otherwise, always returns -1 to signal that the stream is closed or at end-of-stream.
- Specified by:
readin classReader- Parameters:
cbuf- The destination buffer.off- The offset at which to start storing characters.len- The maximum number of characters to read.- Returns:
0iflen == 0; otherwise always -1.- Throws:
IndexOutOfBoundsException- Ifoff < 0,len < 0, oroff + len > cbuf.length.
- If
-
INSTANCE.