Interface MediaTypeDetector


public interface MediaTypeDetector
Detect media type. Minimal implementation checks result based on file suffix.

If suffix is not sufficient, you can use detectType(String), or implement each of the methods.

  • Method Details

    • detectType

      default Optional<MediaType> detectType(URL url)
      Detect type based on a URL. Default implementation uses the URL.getPath() and invokes the detectType(String).
      Parameters:
      url - to find media type from
      Returns:
      media type if detected
    • detectType

      default Optional<MediaType> detectType(URI uri)
      Detect type based on a URL. Default implementation uses the URI.getPath() and invokes the detectType(String).
      Parameters:
      uri - to find media type from
      Returns:
      media type if detected
    • detectType

      default Optional<MediaType> detectType(Path file)
      Detect type based on a Path. Default implementation uses the Path.getFileName() as a String and invokes the detectType(String).
      Parameters:
      file - to find media type from
      Returns:
      media type if detected
    • detectType

      default Optional<MediaType> detectType(String fileString)
      Detect type based on a file string. This may be any string that ends with a file name. Default implementation looks for a suffix (last part of the file string separated by a dot) and if found, invokes the detectExtensionType(String).
      Parameters:
      fileString - path, or name of the file to analyze
      Returns:
      media type if detected
    • detectExtensionType

      Optional<MediaType> detectExtensionType(String fileSuffix)
      Detect media type from a file suffix.

      Example: If the suffix is txt, this method should return text/plain if this detector cares about text files.

      Parameters:
      fileSuffix - suffix (extension) of a file, without the leading dot
      Returns:
      media type if detected