Interface MediaType

All Superinterfaces:
Writeable

@PublicApi(since="2.1.0") public interface MediaType extends Writeable
Abstracts a Media Type and a format parameter. Media types are used as values on Content-Type and Accept headers format is an URL parameter, specifies response media type.
Opensearch.api:
  • Method Details

    • type

      String type()
      Returns a type part of a MediaType i.e. application for application/json
    • subtype

      String subtype()
      Returns a subtype part of a MediaType. i.e. json for application/json
    • format

      String format()
      Returns a corresponding format for a MediaType. i.e. json for application/json media type Can differ from the MediaType's subtype i.e plain/text has a subtype of text but format is txt
    • typeWithSubtype

      default String typeWithSubtype()
      returns a string representation of a media type.
    • xContent

      XContent xContent()
    • detectedXContent

      boolean detectedXContent(byte[] bytes, int offset, int length)
    • detectedXContent

      boolean detectedXContent(CharSequence content, int length)
    • mediaType

      default String mediaType()
    • mediaTypeWithoutParameters

      String mediaTypeWithoutParameters()
    • contentBuilder

      XContentBuilder contentBuilder() throws IOException
      Throws:
      IOException
    • contentBuilder

      XContentBuilder contentBuilder(OutputStream os) throws IOException
      Throws:
      IOException
    • fromFormat

      static MediaType fromFormat(String mediaType)
      Accepts a format string, which is most of the time is equivalent to subtype() and attempts to match the value to an MediaType. The comparisons are done in lower case format. This method will return null if no match is found
    • fromMediaType

      static MediaType fromMediaType(String mediaTypeHeaderValue)
      Attempts to match the given media type with the known MediaType values. This match is done in a case-insensitive manner. The provided media type can optionally has parameters. This method is suitable for parsing of the Content-Type and Accept HTTP headers. This method will return null if no match is found