javatools.filehandlers
Class MatchReader

java.lang.Object
  extended by javatools.datatypes.PeekIterator<java.util.regex.MatchResult>
      extended by javatools.filehandlers.MatchReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Iterable<java.util.regex.MatchResult>, java.util.Iterator<java.util.regex.MatchResult>
Direct Known Subclasses:
ByteMatchReader

public class MatchReader
extends PeekIterator<java.util.regex.MatchResult>
implements java.io.Closeable

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The MatchReader reads MatchResults from a file. It closes the Reader automatically if hasNext()==false. The MatchReader buffers always 1000 characters of the file, i.e. it can work with large files without caching them in total.
Example:

  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.


Nested Class Summary
static class MatchReader.MyMatchResult
          A MatchResult that undoes the quotes
 
Nested classes/interfaces inherited from class javatools.datatypes.PeekIterator
PeekIterator.ElementaryPeekIterator<T>, PeekIterator.SimplePeekIterator<T>
 
Field Summary
 int BUFSIZE
          Number of newly read chars
 int MAXPATTERNLENGTH
          Maximal length of a String matching a pattern
static java.lang.String QUOTE
          Holds the string that quotes are replaced by
 
Fields inherited from class javatools.datatypes.PeekIterator
closed, initialized, next
 
Constructor Summary
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
 
Method Summary
 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
 
Methods inherited from class javatools.datatypes.PeekIterator
asList, asList, asSet, asSet, asSet, emptyIterator, hasNext, iterator, list, list, next, nextOrNull, numElements, numElements, peek, remove, toString, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BUFSIZE

public final int BUFSIZE
Number of newly read chars

See Also:
Constant Field Values

MAXPATTERNLENGTH

public final int MAXPATTERNLENGTH
Maximal length of a String matching a pattern

See Also:
Constant Field Values

QUOTE

public static final java.lang.String QUOTE
Holds the string that quotes are replaced by

See Also:
Constant Field Values
Constructor Detail

MatchReader

public MatchReader(java.io.Reader i,
                   java.util.regex.Pattern p)
Constructs a MatchReader from a Reader and a Pattern


MatchReader

public MatchReader(java.io.Reader i,
                   java.lang.String p)
Constructs a MatchReader from a Reader and a Pattern


MatchReader

public MatchReader(java.io.File f,
                   java.util.regex.Pattern p,
                   java.lang.String announceMsg)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file, with progress message (main constructor)

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.lang.String f,
                   java.util.regex.Pattern p,
                   java.lang.String announceMsg)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file, with progress message

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.lang.String f,
                   java.lang.String p,
                   java.lang.String announceMsg)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file, with progress message

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.io.File f,
                   java.lang.String p,
                   java.lang.String announceMsg)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file, with progress message

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.io.File f,
                   java.lang.String p,
                   boolean crossLines)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.io.File f,
                   java.lang.String p)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.lang.String f,
                   java.lang.String p)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.lang.String f,
                   java.util.regex.Pattern p)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file

Throws:
java.io.FileNotFoundException

MatchReader

public MatchReader(java.io.File f,
                   java.util.regex.Pattern p)
            throws java.io.FileNotFoundException
Constructs a MatchReader that reads from a file

Throws:
java.io.FileNotFoundException
Method Detail

internalNext

public java.util.regex.MatchResult internalNext()
Returns the next MatchResult


close

public void close()
Closes the reader

Specified by:
close in interface java.io.Closeable
Overrides:
close in class PeekIterator<java.util.regex.MatchResult>

finalize

public void finalize()
Closes the reader

Overrides:
finalize in class java.lang.Object

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Test routine

Throws:
java.lang.Exception