public class MatchReader extends PeekIterator<java.util.regex.MatchResult> implements java.io.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 java.lang.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 java.io.Reader |
in
Holds the Reader
|
protected int |
lastMatchEnd
Points to the index of the last match
|
protected java.util.regex.Matcher |
matcher
Holds the current matcher
|
int |
MAXPATTERNLENGTH
Maximal length of a String matching a pattern
|
protected java.util.regex.Pattern |
pattern
Holds the pattern to be found
|
static java.lang.String |
QUOTE
Holds the string that quotes are replaced by
|
closed, EMPTY, initialized, next| Modifier | Constructor and Description |
|---|---|
protected |
MatchReader()
For subclasses
|
|
MatchReader(java.io.File f,
java.util.regex.Pattern p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(java.io.File f,
java.util.regex.Pattern p,
java.lang.String announceMsg)
Constructs a MatchReader that reads from a file, with progress message (main constructor)
|
|
MatchReader(java.io.File f,
java.lang.String p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(java.io.File f,
java.lang.String p,
boolean crossLines)
Constructs a MatchReader that reads from a file
|
|
MatchReader(java.io.File f,
java.lang.String p,
java.lang.String announceMsg)
Constructs a MatchReader that reads from a file, with progress message
|
|
MatchReader(java.io.Reader i,
java.util.regex.Pattern p)
Constructs a MatchReader from a Reader and a Pattern
|
|
MatchReader(java.io.Reader i,
java.lang.String p)
Constructs a MatchReader from a Reader and a Pattern
|
|
MatchReader(java.lang.String f,
java.util.regex.Pattern p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(java.lang.String f,
java.util.regex.Pattern p,
java.lang.String announceMsg)
Constructs a MatchReader that reads from a file, with progress message
|
|
MatchReader(java.lang.String f,
java.lang.String p)
Constructs a MatchReader that reads from a file
|
|
MatchReader(java.lang.String f,
java.lang.String p,
java.lang.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
|
java.util.regex.MatchResult |
internalNext()
Returns the next MatchResult
|
static void |
main(java.lang.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, toStringpublic final int BUFSIZE
public final int MAXPATTERNLENGTH
protected java.io.Reader in
protected java.util.regex.Matcher matcher
protected java.lang.StringBuilder buffer
protected java.util.regex.Pattern pattern
protected long chars
protected int lastMatchEnd
public static final java.lang.String QUOTE
protected boolean crossLines
public MatchReader(java.io.Reader i,
java.util.regex.Pattern p)
public MatchReader(java.io.Reader i,
java.lang.String p)
public MatchReader(java.io.File f,
java.util.regex.Pattern p,
java.lang.String announceMsg)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.lang.String f,
java.util.regex.Pattern p,
java.lang.String announceMsg)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.lang.String f,
java.lang.String p,
java.lang.String announceMsg)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.io.File f,
java.lang.String p,
java.lang.String announceMsg)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.io.File f,
java.lang.String p,
boolean crossLines)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.io.File f,
java.lang.String p)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.lang.String f,
java.lang.String p)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.lang.String f,
java.util.regex.Pattern p)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic MatchReader(java.io.File f,
java.util.regex.Pattern p)
throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionprotected MatchReader()
protected int read()
throws java.io.IOException
java.io.IOExceptionpublic java.util.regex.MatchResult internalNext()
internalNext in class PeekIterator<java.util.regex.MatchResult>public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class PeekIterator<java.util.regex.MatchResult>public void finalize()
finalize in class java.lang.Objectpublic static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception