private static Map<Integer, String> findHeaders(String text) {
        Map<Integer, String> headers = new TreeMap<>();

        Pattern pattern = Pattern.compile(REGEX_HEADER);
        Matcher matcher = pattern.matcher(text);

        while (matcher.find()) {
            headers.put(matcher.start(), matcher.group());
        }

        return headers;
    }
This method helps to find the headers within the given text.

@param text the text from which the headers are extracted.
@return the list of headers found within the given text.
tika-core/src/main/java/org/apache/tika/sax/StandardsText.java