final TermToBytesRefAttribute termAtt = tokenStream.getAttribute(TermToBytesRefAttribute.class);
final BytesRef bytes = termAtt.getBytesRef();
while (termAtt.incrementToken() {
// you must call termAtt.fillBytesRef() before doing something with the bytes.
// this encodes the term value (internally it might be a char[], etc) into the bytes.
int hashCode = termAtt.fillBytesRef();
if (isInteresting(bytes)) {
// because the bytes are reused by the attribute (like CharTermAttribute's char[] buffer),
// you should make a copy if you need persistent access to the bytes, otherwise they will
// be rewritten across calls to incrementToken()
doSomethingWith(new BytesRef(bytes));
}
}
...

WARNING: This API is experimental and might change in incompatible ways in the next release.

This is a very expert API, please use
CharTermAttributeImpl and its implementation of this method
for UTF-8 terms.