public MediaType detect(InputStream input, Metadata metadata) throws IOException {

        List<MimeType> possibleTypes = new ArrayList<>();

        // Get type based on magic prefix
        if (input != null) {
            input.mark(mimeTypes.getMinLength());
            try {
                byte[] prefix = mimeTypes.readMagicHeader(input);
                //defensive copy
                possibleTypes.addAll(mimeTypes.getMimeType(prefix));
            } finally {
                input.reset();
            }
        }

        MimeType extHint = null;
        // Get type based on resourceName hint (if available)
        String resourceName = metadata.get(TikaCoreProperties.RESOURCE_NAME_KEY);
        if (resourceName != null) {
            String name = null;

            // Deal with a URI or a path name in as the resource name
            try {
                URI uri = new URI(resourceName);
                String path = uri.getPath();
                if (path != null) {
                    int slash = path.lastIndexOf('/');
                    if (slash + 1 < path.length()) {
                        name = path.substring(slash + 1);
                    }
                }
            } catch (URISyntaxException e) {
                name = resourceName;
            }

            if (name != null) {
                // MimeType hint = getMimeType(name);
                extHint = mimeTypes.getMimeType(name);
                // If we have some types based on mime magic, try to specialise
                // and/or select the type based on that
                // Otherwise, use the type identified from the name
                // possibleTypes = applyHint(possibleTypes, hint);
            }
        }

        // Get type based on metadata hint (if available)
        MimeType metaHint = null;
        String typeName = metadata.get(Metadata.CONTENT_TYPE);
        if (typeName != null) {
            try {
                // MimeType hint = forName(typeName);
                metaHint = mimeTypes.forName(typeName);
                // possibleTypes = applyHint(possibleTypes, hint);
            } catch (MimeTypeException e) {
                // Malformed type name, ignore
            }
        }

        /*
         * the following calls the probability selection.
         */
        return applyProbilities(possibleTypes, extHint, metaHint);
    }
Initilize probability parameters with default values;
tika-core/src/main/java/org/apache/tika/mime/ProbabilisticMimeDetectionSelector.java