Class MediaTypes


  • public final class MediaTypes
    extends Object
    Media type detection based on a resource.

    The media type detection uses the following algorithm:

    • Queries MediaTypeDetector services in priority order
    • Checks all META-INF/media-types.properties files on classpath for a mapping (suffix=media type)
    • Checks built-in mapping provided by Helidon (with the usual the web relevant media types)
    • Method Detail

      • detectType

        public static Optional<String> detectType​(URL url)
        Detect media type based on URL. As there may be an infinite number of urls used in a system, the results are NOT cached.
        Parameters:
        url - to determine media type for
        Returns:
        media type or empty if none found
      • detectType

        public static Optional<String> detectType​(URI uri)
        Detect media type based on URI. Results may not be cached.
        Parameters:
        uri - to determine media type for
        Returns:
        media type or empty if none found
      • detectType

        public static Optional<String> detectType​(Path file)
        Detect media type for a file on file system. Results may not be cached.
        Parameters:
        file - file on a file system
        Returns:
        media type or empty if none found
      • detectExtensionType

        public static Optional<String> detectExtensionType​(String fileSuffix)
        Detecd media type for a specific file extension. Results are cached.
        Parameters:
        fileSuffix - suffix of a file, such as txt, properties, or jpeg. Without the leading dot.
        Returns:
        media type for the file suffix or empty if none found