Implemented CharSequenceReader.ready
MODIFY
src/main/java/org/apache/commons/io/input/CharSequenceReader.java
src/main/java/org/apache/commons/io/input/CharSequenceReader.java
@@ -165,6 +165,16 @@ public void close() {
mark = start;
}
+ /**
+ * Tells whether this stream is ready to be read.
+ *
+ * @return {@code true} if more characters from the character sequence are available, or {@code false} otherwise.
+ */
+ @Override
+ public boolean ready() {
+ return idx < end();
+ }
+
/**
* Mark the current position.
*

MODIFY
src/test/java/org/apache/commons/io/input/CharSequenceReaderTest.java
src/test/java/org/apache/commons/io/input/CharSequenceReaderTest.java
package org.apache.commons.io.input;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,6 +52,43 @@ public void testClose() throws IOException {
checkRead(subReader, "Foo");
}
+ @Test
+ public void testReady() throws IOException {
+ final Reader reader = new CharSequenceReader("FooBar");
+ assertTrue(reader.ready());
+ reader.skip(3);
+ assertTrue(reader.ready());
+ checkRead(reader, "Bar");
+ assertFalse(reader.ready());
+ reader.reset();
+ assertTrue(reader.ready());
+ reader.skip(2);
+ assertTrue(reader.ready());
+ reader.skip(10);
+ assertFalse(reader.ready());
+ reader.close();
+ assertTrue(reader.ready());
+ reader.skip(20);
+ assertFalse(reader.ready());
+
+ final Reader subReader = new CharSequenceReader("xFooBarx", 1, 7);
+ assertTrue(subReader.ready());
+ subReader.skip(3);
+ assertTrue(subReader.ready());
+ checkRead(subReader, "Bar");
+ assertFalse(subReader.ready());
+ subReader.reset();
+ assertTrue(subReader.ready());
+ subReader.skip(2);
+ assertTrue(subReader.ready());
+ subReader.skip(10);
+ assertFalse(subReader.ready());
+ subReader.close();
+ assertTrue(subReader.ready());
+ subReader.skip(20);
+ assertFalse(subReader.ready());
+ }
+
@Test
public void testMarkSupported() throws Exception {
try (final Reader reader = new CharSequenceReader("FooBar")) {

Implemented CharSequenceReader.ready (#122)