Add a SequenceReader similar to java.io.SequenceInputStream.
Refactor commmon code in a private method.
*/
public SequenceReader(final Iterable<? extends Reader> readers) {
this.readers = Objects.requireNonNull(readers, "readers").iterator();
- this.reader = this.readers.hasNext() ? this.readers.next() : null;
+ this.reader = nextReader();
}
/**
@@ -64,6 +64,10 @@ public void close() throws IOException {
this.reader = null;
}
+ private Reader nextReader() {
+ return this.readers.hasNext() ? this.readers.next() : null;
+ }
+
/*
* (non-Javadoc)
*
@@ -75,7 +79,7 @@ public int read() throws IOException {
while (reader != null) {
c = reader.read();
if (c == EOF) {
- reader = readers.hasNext() ? readers.next() : null;
+ reader = nextReader();
} else {
break;
}
@@ -98,7 +102,7 @@ public int read(final char[] cbuf, int off, int len) throws IOException {
while (reader != null) {
final int readLen = reader.read(cbuf, off, len);
if (readLen == EOF) {
- reader = readers.hasNext() ? readers.next() : null;
+ reader = nextReader();
} else {
count += readLen;
off += readLen;
