private String compile(String glob) {
        StringBuilder pattern = new StringBuilder();
        pattern.append("\\A");
        for (int i = 0; i < glob.length(); i++) {
            char ch = glob.charAt(i);
            if (ch == '?') {
                pattern.append('.');
            } else if (ch == '*') {
                pattern.append(".*");
            } else if ("\\[]^.-$+(){}|".indexOf(ch) != -1) {
                pattern.append('\\');
                pattern.append(ch);
            } else {
                pattern.append(ch);
            }
        }
        pattern.append("\\z");
        return pattern.toString();
    }
Find the MimeType corresponding to a resource name.
<p>
It applies the recommendations detailed in FreeDesktop Shared MIME-info
Database for guessing MimeType from a resource name: It first tries a
case-sensitive match, then try again with the resource name converted to
lower-case if that fails. If several patterns match then the longest
pattern is used. In particular, files with multiple extensions (such as
Data.tar.gz) match the longest sequence of extensions (eg '*.tar.gz' in
preference to '*.gz'). Literal patterns (eg, 'Makefile') are matched
before all others. Patterns beginning with `*.' and containing no other
special characters (`*?[') are matched before other wildcarded patterns
(since this covers the majority of the patterns).
tika-core/src/main/java/org/apache/tika/mime/Patterns.java