org.apache.olingo.commons.api.format

## Class ContentType

- java.lang.Object
- - org.apache.olingo.commons.api.format.ContentType

-     public final class ContentType
      extends Object

  Internally used `ContentType` for OData library. For more details on format and content of a `ContentType` see Media Type format as defined in RFC 7231, chapter 3.1.1.1.

       media-type = type "/" subtype *( OWS ";" OWS parameter )
       type = token
       subtype = token
       OWS = *( SP / HTAB ) ; optional whitespace
       parameter = token "=" ( token / quoted-string )

  Once created a `ContentType` is IMMUTABLE.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ContentType` | `APPLICATION_ATOM_SVC`
    `static ContentType` | `APPLICATION_ATOM_XML`
    `static ContentType` | `APPLICATION_ATOM_XML_ENTRY`
    `static ContentType` | `APPLICATION_ATOM_XML_ENTRY_UTF8`
    `static ContentType` | `APPLICATION_ATOM_XML_FEED`
    `static ContentType` | `APPLICATION_ATOM_XML_FEED_UTF8`
    `static ContentType` | `APPLICATION_FORM_URLENCODED`
    `static ContentType` | `APPLICATION_HTTP`
    `static ContentType` | `APPLICATION_JSON`
    `static ContentType` | `APPLICATION_OCTET_STREAM`
    `static ContentType` | `APPLICATION_SVG_XML`
    `static ContentType` | `APPLICATION_XHTML_XML`
    `static ContentType` | `APPLICATION_XML`
    `static ContentType` | `JSON`
    `static ContentType` | `JSON_FULL_METADATA`
    `static ContentType` | `JSON_NO_METADATA`
    `static ContentType` | `MULTIPART_FORM_DATA`
    `static ContentType` | `MULTIPART_MIXED`
    `static String` | `PARAMETER_CHARSET`
    `static String` | `PARAMETER_IEEE754_COMPATIBLE`
    `static String` | `PARAMETER_ODATA_METADATA`
    `static ContentType` | `TEXT_HTML`
    `static ContentType` | `TEXT_PLAIN`
    `static ContentType` | `TEXT_XML`
    `static String` | `VALUE_ODATA_METADATA_FULL`
    `static String` | `VALUE_ODATA_METADATA_MINIMAL`
    `static String` | `VALUE_ODATA_METADATA_NONE`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ContentType` | `create(ContentType contentType, String parameterName, String parameterValue)` Creates a content type from an existing content type and an additional parameter as key-value pair.
    `static ContentType` | `create(String format)` Creates a `ContentType` based on given input string (`format`).
    `boolean` | `equals(Object obj)` `ContentType`s are equal if `type`, `subtype`, and all `parameters` have the same value.
    `String` | `getParameter(String name)` Returns the value of a given parameter.
    `Map<String,String>` | `getParameters()` Gets the parameters of this content type.
    `String` | `getSubtype()` Gets the subtype of this content type.
    `String` | `getType()` Gets the type of this content type.
    `int` | `hashCode()`
    `boolean` | `isCompatible(ContentType other)` `ContentType`s are compatible if `type` and `subtype` have the same value.
    `static ContentType` | `parse(String format)` Parses the given input string (`format`) and returns created `ContentType` if input was valid or return `NULL` if input was not parseable.
    `String` | `toContentTypeString()` Gets `ContentType` as string as defined in RFC 7231, chapter 3.1.1.1: Media Type.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### PARAMETER_CHARSET

          public static final String PARAMETER_CHARSET

      See Also:
        Constant Field Values

    - #### PARAMETER_IEEE754_COMPATIBLE

          public static final String PARAMETER_IEEE754_COMPATIBLE

      See Also:
        Constant Field Values

    - #### PARAMETER_ODATA_METADATA

          public static final String PARAMETER_ODATA_METADATA

      See Also:
        Constant Field Values

    - #### VALUE_ODATA_METADATA_NONE

          public static final String VALUE_ODATA_METADATA_NONE

      See Also:
        Constant Field Values

    - #### VALUE_ODATA_METADATA_MINIMAL

          public static final String VALUE_ODATA_METADATA_MINIMAL

      See Also:
        Constant Field Values

    - #### VALUE_ODATA_METADATA_FULL

          public static final String VALUE_ODATA_METADATA_FULL

      See Also:
        Constant Field Values

    - #### APPLICATION_JSON

          public static final ContentType APPLICATION_JSON

    - #### JSON

          public static final ContentType JSON

    - #### JSON_NO_METADATA

          public static final ContentType JSON_NO_METADATA

    - #### JSON_FULL_METADATA

          public static final ContentType JSON_FULL_METADATA

    - #### APPLICATION_XML

          public static final ContentType APPLICATION_XML

    - #### APPLICATION_ATOM_XML

          public static final ContentType APPLICATION_ATOM_XML

    - #### APPLICATION_ATOM_XML_ENTRY

          public static final ContentType APPLICATION_ATOM_XML_ENTRY

    - #### APPLICATION_ATOM_XML_ENTRY_UTF8

          public static final ContentType APPLICATION_ATOM_XML_ENTRY_UTF8

    - #### APPLICATION_ATOM_XML_FEED

          public static final ContentType APPLICATION_ATOM_XML_FEED

    - #### APPLICATION_ATOM_XML_FEED_UTF8

          public static final ContentType APPLICATION_ATOM_XML_FEED_UTF8

    - #### APPLICATION_ATOM_SVC

          public static final ContentType APPLICATION_ATOM_SVC

    - #### APPLICATION_OCTET_STREAM

          public static final ContentType APPLICATION_OCTET_STREAM

    - #### APPLICATION_XHTML_XML

          public static final ContentType APPLICATION_XHTML_XML

    - #### TEXT_HTML

          public static final ContentType TEXT_HTML

    - #### TEXT_XML

          public static final ContentType TEXT_XML

    - #### TEXT_PLAIN

          public static final ContentType TEXT_PLAIN

    - #### APPLICATION_SVG_XML

          public static final ContentType APPLICATION_SVG_XML

    - #### APPLICATION_FORM_URLENCODED

          public static final ContentType APPLICATION_FORM_URLENCODED

    - #### APPLICATION_HTTP

          public static final ContentType APPLICATION_HTTP

    - #### MULTIPART_MIXED

          public static final ContentType MULTIPART_MIXED

    - #### MULTIPART_FORM_DATA

          public static final ContentType MULTIPART_FORM_DATA

  - ### Method Detail

    - #### create

          public static ContentType create(ContentType contentType,
                                           String parameterName,
                                           String parameterValue)
                                    throws IllegalArgumentException

      Creates a content type from an existing content type and an additional parameter as key-value pair.
      Parameters:
        `contentType` - an existing content type
        `parameterName` - the name of the additional parameter
        `parameterValue` - the value of the additional parameter
      Returns:
        a new `ContentType` object
      Throws:
        `IllegalArgumentException`

    - #### create

          public static ContentType create(String format)
                                    throws IllegalArgumentException

      Creates a `ContentType` based on given input string (`format`). Supported format is `Media Type` format as defined in RFC 7231, chapter 3.1.1.1.
      Parameters:
        `format` - a string in format as defined in RFC 7231, chapter 3.1.1.1
      Returns:
        a new `ContentType` object
      Throws:
        `IllegalArgumentException` - if input string is not parseable

    - #### parse

          public static ContentType parse(String format)

      Parses the given input string (`format`) and returns created `ContentType` if input was valid or return `NULL` if input was not parseable. For the definition of the supported format see `create(String)`.
      Parameters:
        `format` - a string in format as defined in RFC 7231, chapter 3.1.1.1
      Returns:
        a new `ContentType` object

    - #### getType

          public String getType()

      Gets the type of this content type.

    - #### getSubtype

          public String getSubtype()

      Gets the subtype of this content type.

    - #### getParameters

          public Map<String,String> getParameters()

      Gets the parameters of this content type.
      Returns:
        parameters of this `ContentType` as unmodifiable map

    - #### getParameter

          public String getParameter(String name)

      Returns the value of a given parameter. If the parameter does not exist the method returns null.
      Parameters:
        `name` - the name of the parameter to get (case-insensitive)
      Returns:
        the value of the parameter or `null` if the parameter is not present

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals(Object obj)

      `ContentType`s are equal if `type`, `subtype`, and all `parameters` have the same value.
      Overrides:
        `equals` in class `Object`

    - #### isCompatible

          public boolean isCompatible(ContentType other)

      `ContentType`s are compatible if `type` and `subtype` have the same value.

      The set `parameters` are always ignored (for compare with parameters see `equals(Object)`).

      Returns:
        `true` if both instances are compatible (see definition above), otherwise `false`.

    - #### toContentTypeString

          public String toContentTypeString()

      Gets `ContentType` as string as defined in RFC 7231, chapter 3.1.1.1: Media Type.
      Returns:
        string representation of `ContentType` object

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2013–2022 The Apache Software Foundation. All rights reserved.