import java.io.*; public class StringPatternFilter extends PatternFilter { private String _str; private int _l; public StringPatternFilter(Reader r, String str) { super(r); _str = str; _l = _str.length(); } protected void test() throws IOException { // we _must_ throw an EndOfStream exception like this // to get around a bug is some implementations // that prevents the stream from being properly // reset when we hit the end of the stream // without this code, the stream appears never to // end -- not a good thing in.mark(1); if (in.read() < 0) { throw new EndOfStream(); } in.reset(); // Read characters, create a string, and // compare. in.mark(_l); char [] rgc = new char [_l]; in.read(rgc); in.reset(); String str = new String(rgc); if (str.equals(_str)) { throw new JunkMailException(_str); } } }