/////// MatchingLines.java /////// import java.io.*; import java.util.Vector; public class MatchingLines extends TextLines { public MatchingLines(String ptrn) { pattern = ptrn; } public MatchingLines(TextLines l, String ptrn) { pattern = ptrn; match(l); } protected MatchingLines() { } public int input(InputStream in) { String s; BufferedReader rdr = new BufferedReader (new InputStreamReader(in)); try { while ( (s = rdr.readLine() ) != null ) if ( s.lastIndexOf(pattern) > -1 ) addLine(s); } catch ( IOException e ) { System.err.println( "TextLines: Error reading input"); return(-1); } return length(); // number of lines read and matched } private int match(TextLines l) { if ( l == null || pattern == null ) { return 0; } int m =0, len = l.length(); String s; StringBuffer b; for (int j = 0; j < len; j++ ) { s = new String(b=l.getLine(j)); m = s.lastIndexOf(pattern); if ( m > -1 ) addLine(b); } return length(); } protected String pattern; }