public CharsetMatch detect() {
//   TODO:  A better implementation would be to copy the detect loop from
//          detectAll(), and cut it short as soon as a match with a high confidence
//          is found.  This is something to be done later, after things are otherwise
//          working.
        CharsetMatch[] matches = detectAll();

        if (matches == null || matches.length == 0) {
            return null;
        }

        return matches[0];
    }
Return the charset that best matches the supplied input data.
<p>
Note though, that because the detection
only looks at the start of the input data,
there is a possibility that the returned charset will fail to handle
the full set of input data.
<p>
Raise an exception if
<ul>
<li>no charset appears to match the data.</li>
<li>no input text has been provided</li>
</ul>

@return a CharsetMatch object representing the best matching charset, or
<code>null</code> if there are no matches.
@stable ICU 3.4
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-text-module/src/main/java/org/apache/tika/parser/txt/CharsetDetector.java