public class MatchReader extends PeekIterator<MatchResult> implements Closeable
MatchReader matchReader=new MatchReader("some Filename", "some Pattern");
for(MatchResult matchResult : matchReader) {
System.out.println(matchResult.group(1));
}
The file is automatically closed after the last match has been read. If you do
not read all matches, close the iterator manually by the method close().A single quote (') preceded by a backslash will not match a quote in the pattern.
| Modifier and Type | Class and Description |
|---|---|
static class |
MatchReader.MyMatchResult
A MatchResult that undoes the quotes
|
PeekIterator.ElementaryPeekIterator<T>, PeekIterator.SimplePeekIterator<T>| Modifier and Type | Field and Description |
|---|---|
protected StringBuilder |
buffer
Holds the current buffer
|
int |
BUFSIZE
Number of newly read chars
|
protected long |
chars
Char counter for Announce.progress
|
protected boolean |
crossLines
TRUE if newlines are to be replaces by spaces
|
protected Reader |
in
Holds the Reader
|
protected int |
lastMatchEnd
Points to the index of the last match
|
protected Matcher |
matcher
Holds the current matcher
|
int |
MAXPATTERNLENGTH
Maximal length of a String matching a pattern
|
protected Pattern |
pattern
Holds the pattern to be found
|
static String |
QUOTE
Holds the string that quotes are replaced by
|
closed, EMPTY, fetchedNextValue, next| Modifier | Constructor and Description |
|---|---|
protected |
MatchReader()
For subclasses
|
|
MatchReader(File f,
Pattern p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(File f,
Pattern p,
String announceMsg)
Constructs a MatchReader that reads from a file, with progress message (main constructor)
|
|
MatchReader(File f,
String p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(File f,
String p,
boolean crossLines)
Constructs a MatchReader that reads from a file
|
|
MatchReader(File f,
String p,
String announceMsg)
Constructs a MatchReader that reads from a file, with progress message
|
|
MatchReader(Reader i,
Pattern p)
Constructs a MatchReader from a Reader and a Pattern
|
|
MatchReader(Reader i,
String p)
Constructs a MatchReader from a Reader and a Pattern
|
|
MatchReader(String f,
Pattern p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(String f,
Pattern p,
String announceMsg)
Constructs a MatchReader that reads from a file, with progress message
|
|
MatchReader(String f,
String p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(String f,
String p,
String announceMsg)
Constructs a MatchReader that reads from a file, with progress message
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the reader
|
void |
finalize()
Closes the reader
|
MatchResult |
internalNext()
Returns the next MatchResult
|
static void |
main(String[] args)
Test routine
|
protected int |
read()
Reads 1 character (simplification for subclass ByteMatchReader)
|
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, internalSilentNext, iterator, list, list, next, nextOrNull, numElements, numElements, peek, remove, toString, toString, toStringclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitforEachRemainingforEach, spliteratorpublic final int BUFSIZE
public final int MAXPATTERNLENGTH
protected Reader in
protected Matcher matcher
protected StringBuilder buffer
protected Pattern pattern
protected long chars
protected int lastMatchEnd
public static final String QUOTE
protected boolean crossLines
public MatchReader(Reader i, Pattern p)
public MatchReader(Reader i, String p)
public MatchReader(File f, Pattern p, String announceMsg) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(String f, Pattern p, String announceMsg) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(String f, String p, String announceMsg) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(File f, String p, String announceMsg) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(File f, String p, boolean crossLines) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(File f, String p) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(String f, String p) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(String f, Pattern p) throws FileNotFoundException
FileNotFoundExceptionpublic MatchReader(File f, Pattern p) throws FileNotFoundException
FileNotFoundExceptionprotected MatchReader()
protected int read()
throws IOException
IOExceptionpublic MatchResult internalNext()
internalNext in class PeekIterator<MatchResult>public void close()
close in interface Closeableclose in interface AutoCloseableclose in class PeekIterator<MatchResult>Copyright © 2018. All rights reserved.