public MediaType detect()

in src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java [34:58]


    public MediaType detect(InputStream rawData, Metadata metadata) {

        // NOTE: This implementation is built after the Tika NameDetector
        //    implementation which only takes the resource name into
        //    consideration when trying to detect the MIME type.

        // Look for a resource name in the input metadata
        String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
        if (name != null) {
            // If the name is a path, skip all but the last component
            int slash = name.lastIndexOf('/');
            if (slash != -1) {
                name = name.substring(slash + 1);
            }
            if (name.length() > 0) {
                // Match the name against the registered patterns
                String type = mimeTypeService.getMimeType(name);
                if (type != null) {
                    return MediaType.parse(type);
                }
            }
        }

        return MediaType.OCTET_STREAM;
    }