Look into FilteredInputStream as a place to put this code.
What do you want to do when you find the string? Is it ok to raise the "found it!" flag after it has already gone by, or do you need to capture it, replace it or remove it or something? (By "raise the flag" I mean take some action ... call a method or whatever.)
This would raise the flag just as the last byte of the search target comes through:
This is going to be really clumsy in pseudo code but it would remove the search target from the stream:
If you have really massive input and a fairly long search target, look up the Boyer Moore search algorithm. It's way too complex to describe here but it's orders of magnitude faster than brute force. The "partial match" test
is very tough on some patterns
, and Boyer Moore handles it brilliantly.
Any of that sound useful?