org.springframework.util

## Class MimeType

- java.lang.Object
- - org.springframework.util.MimeType

- All Implemented Interfaces:
    Serializable, Comparable<MimeType>
  Direct Known Subclasses:
    MediaType

      public class MimeType
      extends Object
      implements Comparable<MimeType>, Serializable

  Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in other Internet protocols including HTTP. This class however does not contain support the q-parameters used in HTTP content negotiation. Those can be found in the sub-class `org.springframework.http.MediaType` in the `spring-web` module.

  Consists of a type and a subtype. Also has functionality to parse media types from a string using `valueOf(String)`. For more parsing options see `MimeTypeUtils`.

  Since:
    4.0
  Author:
    Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
  See Also:
    `MimeTypeUtils`, Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MimeType.SpecificityComparator<T extends MimeType>`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `WILDCARD_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MimeType(MimeType other, Map<String,String> parameters)` Copy-constructor that copies the type and subtype of the given `MimeType`, and allows for different parameter.
    `MimeType(String type)` Create a new `MimeType` for the given primary type.
    `MimeType(String type, String subtype)` Create a new `MimeType` for the given primary type and subtype.
    `MimeType(String type, String subtype, Charset charSet)` Create a new `MimeType` for the given type, subtype, and character set.
    `MimeType(String type, String subtype, Map<String,String> parameters)` Create a new `MimeType` for the given type, subtype, and parameters.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `appendTo(StringBuilder builder)`
    `protected void` | `checkParameters(String attribute, String value)`
    `int` | `compareTo(MimeType other)` Compares this `MediaType` to another alphabetically.
    `boolean` | `equals(Object other)`
    `Charset` | `getCharSet()` Return the character set, as indicated by a `charset` parameter, if any.
    `String` | `getParameter(String name)` Return a generic parameter value, given a parameter name.
    `Map<String,String>` | `getParameters()` Return all generic parameter values.
    `String` | `getSubtype()` Return the subtype.
    `String` | `getType()` Return the primary type.
    `int` | `hashCode()`
    `boolean` | `includes(MimeType other)` Indicate whether this `MediaType` includes the given media type.
    `boolean` | `isCompatibleWith(MimeType other)` Indicate whether this `MediaType` is compatible with the given media type.
    `boolean` | `isConcrete()` Indicates whether this media type is concrete, i.e.
    `boolean` | `isWildcardSubtype()` Indicates whether the subtype is the wildcard character `&#42;` or the wildcard character followed by a sufiix (e.g.
    `boolean` | `isWildcardType()` Indicates whether the type is the wildcard character `&#42;` or not.
    `String` | `toString()`
    `protected String` | `unquote(String s)`
    `static MimeType` | `valueOf(String value)` Parse the given String value into a `MimeType` object, with this method name following the 'valueOf' naming convention (as supported by `ConversionService`.

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

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

- - ### Field Detail

    - #### WILDCARD_TYPE

          protected static final String WILDCARD_TYPE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### MimeType

          public MimeType(String type)

      Create a new `MimeType` for the given primary type.

      The subtype is set to "*", parameters empty.

      Parameters:
        `type` - the primary type
      Throws:
        `IllegalArgumentException` - if any of the parameters contain illegal characters

    - #### MimeType

          public MimeType(String type,
                          String subtype)

      Create a new `MimeType` for the given primary type and subtype.

      The parameters are empty.

      Parameters:
        `type` - the primary type
        `subtype` - the subtype
      Throws:
        `IllegalArgumentException` - if any of the parameters contain illegal characters

    - #### MimeType

          public MimeType(String type,
                          String subtype,
                          Charset charSet)

      Create a new `MimeType` for the given type, subtype, and character set.
      Parameters:
        `type` - the primary type
        `subtype` - the subtype
        `charSet` - the character set
      Throws:
        `IllegalArgumentException` - if any of the parameters contain illegal characters

    - #### MimeType

          public MimeType(MimeType other,
                          Map<String,String> parameters)

      Copy-constructor that copies the type and subtype of the given `MimeType`, and allows for different parameter.
      Parameters:
        `other` - the other media type
        `parameters` - the parameters, may be `null`
      Throws:
        `IllegalArgumentException` - if any of the parameters contain illegal characters

    - #### MimeType

          public MimeType(String type,
                          String subtype,
                          Map<String,String> parameters)

      Create a new `MimeType` for the given type, subtype, and parameters.
      Parameters:
        `type` - the primary type
        `subtype` - the subtype
        `parameters` - the parameters, may be `null`
      Throws:
        `IllegalArgumentException` - if any of the parameters contain illegal characters

  - ### Method Detail

    - #### checkParameters

          protected void checkParameters(String attribute,
                                         String value)

    - #### unquote

          protected String unquote(String s)

    - #### isWildcardType

          public boolean isWildcardType()

      Indicates whether the type is the wildcard character `&#42;` or not.

    - #### isWildcardSubtype

          public boolean isWildcardSubtype()

      Indicates whether the subtype is the wildcard character `&#42;` or the wildcard character followed by a sufiix (e.g. `&#42;+xml`), or not.
      Returns:
        whether the subtype is `&#42;`

    - #### isConcrete

          public boolean isConcrete()

      Indicates whether this media type is concrete, i.e. whether neither the type or subtype is a wildcard character `&#42;`.
      Returns:
        whether this media type is concrete

    - #### getType

          public String getType()

      Return the primary type.

    - #### getSubtype

          public String getSubtype()

      Return the subtype.

    - #### getCharSet

          public Charset getCharSet()

      Return the character set, as indicated by a `charset` parameter, if any.
      Returns:
        the character set; or `null` if not available

    - #### getParameter

          public String getParameter(String name)

      Return a generic parameter value, given a parameter name.
      Parameters:
        `name` - the parameter name
      Returns:
        the parameter value; or `null` if not present

    - #### getParameters

          public Map<String,String> getParameters()

      Return all generic parameter values.
      Returns:
        a read-only map, possibly empty, never `null`

    - #### includes

          public boolean includes(MimeType other)

      Indicate whether this `MediaType` includes the given media type.

      For instance, `text/*` includes `text/plain` and `text/html`, and `application/*+xml` includes `application/soap+xml`, etc. This method is not symmetric.

      Parameters:
        `other` - the reference media type with which to compare
      Returns:
        `true` if this media type includes the given media type; `false` otherwise

    - #### isCompatibleWith

          public boolean isCompatibleWith(MimeType other)

      Indicate whether this `MediaType` is compatible with the given media type.

      For instance, `text/*` is compatible with `text/plain`, `text/html`, and vice versa. In effect, this method is similar to `includes(org.springframework.util.MimeType)`, except that it is symmetric.

      Parameters:
        `other` - the reference media type with which to compare
      Returns:
        `true` if this media type is compatible with the given media type; `false` otherwise

    - #### compareTo

          public int compareTo(MimeType other)

      Compares this `MediaType` to another alphabetically.
      Specified by:
        `compareTo` in interface `Comparable<MimeType>`
      Parameters:
        `other` - media type to compare to
      See Also:
        `MimeTypeUtils.sortBySpecificity(List)`

    - #### equals

          public boolean equals(Object other)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### appendTo

          protected void appendTo(StringBuilder builder)

    - #### valueOf

          public static MimeType valueOf(String value)

      Parse the given String value into a `MimeType` object, with this method name following the 'valueOf' naming convention (as supported by `ConversionService`.
      See Also:
        `MimeTypeUtils.parseMimeType(String)`