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)
  • Field Details

    • WILDCARD

      public static final MediaType WILDCARD
      Wildcard media type.
    • APPLICATION_XML

      public static final MediaType APPLICATION_XML
      application/xml media type.
    • APPLICATION_ATOM_XML

      public static final MediaType APPLICATION_ATOM_XML
      application/atom+xml media type.
    • APPLICATION_XHTML_XML

      public static final MediaType APPLICATION_XHTML_XML
      application/xhtml+xml media type.
    • APPLICATION_SVG_XML

      public static final MediaType APPLICATION_SVG_XML
      application/svg+xml media type.
    • APPLICATION_JSON

      public static final MediaType APPLICATION_JSON
      application/json media type.
    • APPLICATION_STREAM_JSON

      public static final MediaType APPLICATION_STREAM_JSON
      application/stream+json media type.
    • APPLICATION_FORM_URLENCODED

      public static final MediaType APPLICATION_FORM_URLENCODED
      application/x-www-form-urlencoded media type.
    • MULTIPART_FORM_DATA

      public static final MediaType MULTIPART_FORM_DATA
      multipart/form-data media type.
    • MULTIPART_BYTERANGES

      public static final MediaType MULTIPART_BYTERANGES
      multipart/byte-ranges media type.
    • APPLICATION_OCTET_STREAM

      public static final MediaType APPLICATION_OCTET_STREAM
      application/octet-stream media type.
    • TEXT_PLAIN

      public static final MediaType TEXT_PLAIN
      tet/plain media type.
    • TEXT_XML

      public static final MediaType TEXT_XML
      text/xml media type.
    • TEXT_HTML

      public static final MediaType TEXT_HTML
      text/html media type.
    • APPLICATION_OPENAPI_YAML

      public static final MediaType APPLICATION_OPENAPI_YAML
      application/vnd.oai.openapi media type.
    • APPLICATION_OPENAPI_JSON

      public static final MediaType APPLICATION_OPENAPI_JSON
      application/vnd.oai.openapi+json media type.
    • APPLICATION_OPENMETRICS_TEXT

      public static final MediaType APPLICATION_OPENMETRICS_TEXT
      application/openmetrics-text media type.
    • APPLICATION_X_YAML

      public static final MediaType APPLICATION_X_YAML
      application/x-yaml media type.
    • APPLICATION_YAML

      public static final MediaType APPLICATION_YAML
      application/yaml media type.
    • TEXT_X_YAML

      public static final MediaType TEXT_X_YAML
      text/x-yaml media type.
    • TEXT_YAML

      public static final MediaType TEXT_YAML
      text/yaml media type.
    • APPLICATION_JAVASCRIPT

      public static final MediaType APPLICATION_JAVASCRIPT
      application/javascript media type.
    • TEXT_EVENT_STREAM

      public static final MediaType TEXT_EVENT_STREAM
      text/event-stream media type.
    • APPLICATION_X_NDJSON

      public static final MediaType APPLICATION_X_NDJSON
      application/x-ndjson media type.
    • APPLICATION_HOCON

      public static final MediaType APPLICATION_HOCON
      application/hocon media type.
  • Method Details

    • create

      public static MediaType create(String type, String subtype)
      Create media type from the type and subtype.
      Parameters:
      type - type
      subtype - subtype
      Returns:
      media type for the instance
    • create

      public static MediaType create(String fullType)
      Create a new media type from the full media type string. Strict media type parsing mode is used.
      Parameters:
      fullType - media type string, such as application/json
      Returns:
      media type for the string
    • create

      public static MediaType create(String fullType, ParserMode parserMode)
      Create a new media type from the full media type string.
      Parameters:
      fullType - media type string, such as application/json
      parserMode - media type parsing mode
      Returns:
      media type for the string
    • detectType

      public static Optional<MediaType> 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<MediaType> 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<MediaType> 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<MediaType> 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<MediaType> 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