java.lang.Object
io.helidon.common.media.type.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 Details

    • 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
    • detectType

      public static Optional<String> detectType(String fileName)
      Detect media type for a path (may be URL, URI, path on a file system). Results may not be cached. If you have URL, URI, or Path please use the other methods on this class.
      Parameters:
      fileName - any string that has a file name as its last element
      Returns:
      media type or empty if none found
      See Also:
    • 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