@Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            sb.append(new String(ch, start, length).toLowerCase(Locale.getDefault()));

            if (sb
                    .toString()
                    .contains(query)) {
                throw new QueryMatchedException();
            }

            if (sb.length() > 2 * query.length()) {
                sb.delete(0, sb.length() - query.length()); // keep tail with query.length() chars
            }
        }
Trivial content handler that searched for {@code query} in characters send to it.
<p>
Throws {@link QueryMatchedException} when query string is found.
tika-example/src/main/java/org/apache/tika/example/InterruptableParsingExample.java