FileDocCategorySizeDatePackage
GrepReader.javaAPI DocExample1929Sat Jun 02 02:41:40 BST 2001None

GrepReader

public class GrepReader extends BufferedReader
This class is a BufferedReader that filters out all lines that do not contain the specified pattern.

Fields Summary
String
pattern
Constructors Summary
public GrepReader(Reader in, String pattern)
Pass the stream to our superclass, and remember the pattern ourself

    super(in);
    this.pattern = pattern;
  
Methods Summary
public final java.lang.StringreadLine()
This is the filter: call our superclass's readLine() to get the actual lines, but only return lines that contain the pattern. When the superclass readLine() returns null (EOF), we return null.

    String line;
    do { line = super.readLine(); }
    while ((line != null) && line.indexOf(pattern) == -1);
    return line;