Package org.apache.axiom.mime

## Class MediaType

- java.lang.Object
- - org.apache.axiom.mime.MediaType

-     public final class MediaType
      extends Object

  Represents a media type as defined by RFC 2045 and RFC 2046. It specifies a primary type (e.g. `text`) and a subtype (e.g. `xml`). Note that in RFC 2045, "media type" refers to what is called "primary type" here, while this class uses "media type" to refer to the combination of primary and subtype.

  This class is immutable. It overrides `Object.equals(Object)` and `Object.hashCode()` to allow comparing media types as described by RFC 2045, i.e. in a case insensitive way.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static MediaType` | `APPLICATION_OCTET_STREAM` | The media type for `application/octet-stream`.
    `static MediaType` | `APPLICATION_SOAP_XML` | The media type for `application/soap+xml`.
    `static MediaType` | `APPLICATION_XML` | The media type for `application/xml`.
    `static MediaType` | `APPLICATION_XOP_XML` | The media type for `application/xop+xml`.
    `static MediaType` | `MULTIPART_RELATED` | The media type for `multipart/related`.
    `static MediaType` | `TEXT_PLAIN` | The media type for `text/plain`.
    `static MediaType` | `TEXT_XML` | The media type for `text/xml`.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `MediaType​(String type)` | Constructor that parses a media type.
    `MediaType​(String primaryType, String subType)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `equals​(Object obj)` |
    `String` | `getPrimaryType()` | Get the primary type.
    `String` | `getSubType()` | Get the subtype.
    `int` | `hashCode()` |
    `boolean` | `hasPrimaryType​(String type)` | Check if this media type has the given primary type.
    `boolean` | `hasSubType​(String type)` | Check if this media type has the given sub type.
    `boolean` | `isXML()` | Check if this media type describes XML content as defined in RFC 7303.
    `String` | `toString()` |

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

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

- - ### Field Detail

    - #### TEXT_XML

          public static final MediaType TEXT_XML

      The media type for `text/xml`.

    - #### APPLICATION_XML

          public static final MediaType APPLICATION_XML

      The media type for `application/xml`.

    - #### APPLICATION_SOAP_XML

          public static final MediaType APPLICATION_SOAP_XML

      The media type for `application/soap+xml`.

    - #### APPLICATION_XOP_XML

          public static final MediaType APPLICATION_XOP_XML

      The media type for `application/xop+xml`.

    - #### MULTIPART_RELATED

          public static final MediaType MULTIPART_RELATED

      The media type for `multipart/related`.

    - #### APPLICATION_OCTET_STREAM

          public static final MediaType APPLICATION_OCTET_STREAM

      The media type for `application/octet-stream`.

    - #### TEXT_PLAIN

          public static final MediaType TEXT_PLAIN

      The media type for `text/plain`.

  - ### Constructor Detail

    - #### MediaType

          public MediaType​(String primaryType,
                           String subType)

      Constructor.
      Parameters:
        `primaryType` - the primary type
        `subType` - the subtype

    - #### MediaType

          public MediaType​(String type)
                    throws ParseException

      Constructor that parses a media type.
      Parameters:
        `type` - the media type to parse
      Throws:
        `ParseException` - if the value is invalid and could not be parsed

  - ### Method Detail

    - #### getPrimaryType

          public String getPrimaryType()

      Get the primary type.
      Returns:
        the primary type

    - #### getSubType

          public String getSubType()

      Get the subtype.
      Returns:
        the subtype

    - #### hasPrimaryType

          public boolean hasPrimaryType​(String type)

      Check if this media type has the given primary type.
      Parameters:
        `type` - the primary type to check against
      Returns:
        whether the primary type matches

    - #### hasSubType

          public boolean hasSubType​(String type)

      Check if this media type has the given sub type.
      Parameters:
        `type` - the sub type to check against
      Returns:
        whether the sub type matches

    - #### isXML

          public boolean isXML()

      Check if this media type describes XML content as defined in RFC 7303.
      Returns:
        whether the content expected for this media type is XML

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### equals

          public boolean equals​(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`