public String getString(byte[] in, String declaredEncoding) {
        fDeclaredEncoding = declaredEncoding;

        try {
            setText(in);

            CharsetMatch match = detect();

            if (match == null) {
                return null;
            }

            return match.getString(-1);
        } catch (IOException e) {
            return null;
        }
    }
Autodetect the charset of an inputStream, and return a String
containing the converted input data.
<p>
This is a convenience method that is equivalent to
<code>this.setDeclaredEncoding(declaredEncoding).setText(in).detect().getString();</code>
<p>
Raise an exception if no charsets appear to match the input data.

@param in               The source of the byte data in the unknown charset.
@param declaredEncoding A declared encoding for the data, if available,
                        or null or an empty string if none is available.
@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