public final class MultiLineReader extends Object implements Iterable<MultiLineReader.Entry>, Closeable
Although MultiLineReader
implements Iterable
, it only supports iterating over the entries once. This iterating can be done using
iterator()
, spliterator()
or entries()
. Only one of these methods may be used per MultiLineReader
instance,
and only once. Attempting to call more than one of these methods, or one of these methods multiple times, will result in an
IllegalStateException
.
Modifier and Type | Class and Description |
---|---|
static class |
MultiLineReader.Entry
An entry that can be read using a
MultiLineReader . |
Constructor and Description |
---|
MultiLineReader(Reader reader,
Pattern newEntryStart)
Creates a new multi-line reader.
|
MultiLineReader(Reader reader,
Predicate<? super String> newEntryStart)
Creates a new multi-line reader.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
Stream<MultiLineReader.Entry> |
entries()
Returns a stream over the entries.
|
Iterator<MultiLineReader.Entry> |
iterator()
Returns an iterator over the entries.
|
Spliterator<MultiLineReader.Entry> |
spliterator()
Returns a
Spliterator over the entries. |
public MultiLineReader(Reader reader, Pattern newEntryStart)
MultiLineReader(reader, newEntryStart.asPredicate())
.reader
- The backing reader.newEntryStart
- The pattern that determines when a line indicates the start of a new entry.NullPointerException
- If the reader or pattern is null
.public MultiLineReader(Reader reader, Predicate<? super String> newEntryStart)
reader
- The backing reader.newEntryStart
- The predicate that determines when a line indicates the start of a new entry.NullPointerException
- If the reader or predicate is null
.public Iterator<MultiLineReader.Entry> iterator()
spliterator()
and entries()
.iterator
in interface Iterable<MultiLineReader.Entry>
IllegalStateException
- If this method is called for a second time,
or if spliterator()
or entries()
has already been called.public Spliterator<MultiLineReader.Entry> spliterator()
Spliterator
over the entries.
This method may be called only once, and may not be used in combination with iterator()
and entries()
.spliterator
in interface Iterable<MultiLineReader.Entry>
Spliterator
over the entries.IllegalStateException
- If this method is called for a second time,
or if spliterator()
or entries()
has already been called.public Stream<MultiLineReader.Entry> entries()
iterator()
and spliterator()
.IllegalStateException
- If this method is called for a second time,
or if iterator()
or spliterator()
has already been called.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2020–2024. All rights reserved.