@Override
    public Charset detect(InputStream input, Metadata metadata) throws IOException {
        int limit = getMarkLimit();
        input.mark(limit);
        // Never read more than the first META_TAG_BUFFER_SIZE bytes
        InputStream limitedStream = BoundedInputStream.builder().setInputStream(input).setMaxCount(limit).get();
        PreScanner preScanner = new PreScanner(limitedStream);

        // The order of priority for detection is:
        // 1. Byte Order Mark
        Charset detectedCharset = preScanner.detectBOM();
        // 2. Transport-level information (Content-Type HTTP header)
        if (detectedCharset == null) {
            detectedCharset = charsetFromContentType(metadata);
        }
        // 3. HTML <meta> tag
        if (detectedCharset == null) {
            detectedCharset = preScanner.scan();
        }

        input.reset();
        return detectedCharset;
    }
Extracts a charset from a Content-Type HTTP header.

@param metadata parser metadata
@return a charset if there is one specified, or null
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/charsetdetector/StandardHtmlEncodingDetector.java