@Override
    public void addText(char[] cbuf, int off, int len) {
        int buffLen = buffer.length();
        int newLen = Math.min(len, detector.getMaxLength() - buffLen);
        if (len <= 0) {
            return;
        }
        buffer.append(cbuf, off, newLen);
    }
This will buffer up to {@link #setMaxLength(int)} and then
ignore the rest of the text.

@param cbuf Character buffer
@param off  Offset into cbuf to first character in the run of text
@param len  Number of characters in the run of text.
tika-langdetect/tika-langdetect-opennlp/src/main/java/org/apache/tika/langdetect/opennlp/OpenNLPDetector.java