Class MimeType
- All Implemented Interfaces:
Serializable
,Comparable<MimeType>
- Direct Known Subclasses:
MediaType
This class, however, does not contain support for the q-parameters used
in HTTP content negotiation. Those can be found in the subclass
org.springframework.http.MediaType
in the spring-web
module.
Consists of a type and a subtype.
Also has functionality to parse MIME Type values from a String
using
valueOf(String)
. For more parsing options see MimeTypeUtils
.
- Since:
- 4.0
- Author:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sam Brannen
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
MimeType.SpecificityComparator<T extends MimeType>
Deprecated, for removal: This API element is subject to removal in a future version.As of 6.0, with no direct replacement -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionCreate a newMimeType
for the given primary type.Create a newMimeType
for the given primary type and subtype.Create a newMimeType
for the given type, subtype, and character set.Create a newMimeType
for the given type, subtype, and parameters.protected
Copy-constructor that copies the type, subtype and parameters of the givenMimeType
, skipping checks performed in other constructors.Copy-constructor that copies the type, subtype, parameters of the givenMimeType
, and allows to set the specified character set.Copy-constructor that copies the type and subtype of the givenMimeType
, and allows for different parameter. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
appendTo
(StringBuilder builder) protected void
checkParameters
(String parameter, String value) int
Compares this MIME Type to another alphabetically.boolean
boolean
equalsTypeAndSubtype
(MimeType other) Similar toequals(Object)
but based on the type and subtype only, i.e.Return the character set, as indicated by acharset
parameter, if any.getParameter
(String name) Return a generic parameter value, given a parameter name.Return all generic parameter values.Return the subtype.Return the subtype suffix as defined in RFC 6839.getType()
Return the primary type.int
hashCode()
boolean
Indicate whether this MIME Type includes the given MIME Type.boolean
isCompatibleWith
(MimeType other) Indicate whether this MIME Type is compatible with the given MIME Type.boolean
Indicates whether this MIME Type is concrete, i.e.boolean
isLessSpecific
(MimeType other) Indicates whether thisMimeType
is more less than the given type.boolean
isMoreSpecific
(MimeType other) Indicates whether thisMimeType
is more specific than the given type.boolean
isPresentIn
(Collection<? extends MimeType> mimeTypes) UnlikeCollection.contains(Object)
which relies onequals(Object)
, this method only checks the type and the subtype, but otherwise ignores parameters.boolean
Indicates whether the subtype is the wildcard character*
or the wildcard character followed by a suffix (e.g.boolean
Indicates whether the type is the wildcard character*
or not.toString()
protected String
static MimeType
Parse the given String value into aMimeType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.
-
Field Details
-
WILDCARD_TYPE
- See Also:
-
-
Constructor Details
-
MimeType
Create a newMimeType
for the given primary type.The subtype is set to
"*"
, and the parameters are empty.- Parameters:
type
- the primary type- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters
-
MimeType
Create a newMimeType
for the given primary type and subtype.The parameters are empty.
- Parameters:
type
- the primary typesubtype
- the subtype- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters
-
MimeType
Create a newMimeType
for the given type, subtype, and character set.- Parameters:
type
- the primary typesubtype
- the subtypecharset
- the character set- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters
-
MimeType
Copy-constructor that copies the type, subtype, parameters of the givenMimeType
, and allows to set the specified character set.- Parameters:
other
- the other MimeTypecharset
- the character set- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters- Since:
- 4.3
-
MimeType
Copy-constructor that copies the type and subtype of the givenMimeType
, and allows for different parameter.- Parameters:
other
- the other MimeTypeparameters
- the parameters (may benull
)- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters
-
MimeType
Create a newMimeType
for the given type, subtype, and parameters.- Parameters:
type
- the primary typesubtype
- the subtypeparameters
- the parameters (may benull
)- Throws:
IllegalArgumentException
- if any of the parameters contains illegal characters
-
MimeType
Copy-constructor that copies the type, subtype and parameters of the givenMimeType
, skipping checks performed in other constructors.- Parameters:
other
- the other MimeType- Since:
- 5.3
-
-
Method Details
-
checkParameters
-
unquote
-
isWildcardType
public boolean isWildcardType()Indicates whether the type is the wildcard character*
or not. -
isWildcardSubtype
public boolean isWildcardSubtype()Indicates whether the subtype is the wildcard character*
or the wildcard character followed by a suffix (e.g.*+xml
).- Returns:
- whether the subtype is a wildcard
-
isConcrete
public boolean isConcrete()Indicates whether this MIME Type is concrete, i.e. whether neither the type nor the subtype is a wildcard character*
.- Returns:
- whether this MIME Type is concrete
-
getType
Return the primary type. -
getSubtype
Return the subtype. -
getSubtypeSuffix
Return the subtype suffix as defined in RFC 6839.- Since:
- 5.3
-
getCharset
Return the character set, as indicated by acharset
parameter, if any.- Returns:
- the character set, or
null
if not available - Since:
- 4.3
-
getParameter
Return a generic parameter value, given a parameter name.- Parameters:
name
- the parameter name- Returns:
- the parameter value, or
null
if not present
-
getParameters
Return all generic parameter values.- Returns:
- a read-only map (possibly empty, never
null
)
-
includes
Indicate whether this MIME Type includes the given MIME Type.For instance,
text/*
includestext/plain
andtext/html
, andapplication/*+xml
includesapplication/soap+xml
, etc. This method is not symmetric.- Parameters:
other
- the reference MIME Type with which to compare- Returns:
true
if this MIME Type includes the given MIME Type;false
otherwise
-
isCompatibleWith
Indicate whether this MIME Type is compatible with the given MIME Type.For instance,
text/*
is compatible withtext/plain
,text/html
, and vice versa. In effect, this method is similar toincludes(org.springframework.util.MimeType)
, except that it is symmetric.- Parameters:
other
- the reference MIME Type with which to compare- Returns:
true
if this MIME Type is compatible with the given MIME Type;false
otherwise
-
equalsTypeAndSubtype
Similar toequals(Object)
but based on the type and subtype only, i.e. ignoring parameters.- Parameters:
other
- the other mime type to compare to- Returns:
- whether the two mime types have the same type and subtype
- Since:
- 5.1.4
-
isPresentIn
UnlikeCollection.contains(Object)
which relies onequals(Object)
, this method only checks the type and the subtype, but otherwise ignores parameters.- Parameters:
mimeTypes
- the list of mime types to perform the check against- Returns:
- whether the list contains the given mime type
- Since:
- 5.1.4
-
equals
-
hashCode
public int hashCode() -
toString
-
appendTo
-
compareTo
Compares this MIME Type to another alphabetically.- Specified by:
compareTo
in interfaceComparable<MimeType>
- Parameters:
other
- the MIME Type to compare to
-
isMoreSpecific
Indicates whether thisMimeType
is more specific than the given type.- if this mime type has a wildcard type,
and the other does not, then this method returns
false
. - if this mime type does not have a wildcard type,
and the other does, then this method returns
true
. - if this mime type has a wildcard type,
and the other does not, then this method returns
false
. - if this mime type does not have a wildcard type,
and the other does, then this method returns
true
. - if the two mime types have identical type and subtype, then the mime type with the most parameters is more specific than the other.
- Otherwise, this method returns
false
.
- Parameters:
other
- theMimeType
to be compared- Returns:
- the result of the comparison
- Since:
- 6.0
- See Also:
- if this mime type has a wildcard type,
and the other does not, then this method returns
-
isLessSpecific
Indicates whether thisMimeType
is more less than the given type.- if this mime type has a wildcard type,
and the other does not, then this method returns
true
. - if this mime type does not have a wildcard type,
and the other does, then this method returns
false
. - if this mime type has a wildcard type,
and the other does not, then this method returns
true
. - if this mime type does not have a wildcard type,
and the other does, then this method returns
false
. - if the two mime types have identical type and subtype, then the mime type with the least parameters is less specific than the other.
- Otherwise, this method returns
false
.
- Parameters:
other
- theMimeType
to be compared- Returns:
- the result of the comparison
- Since:
- 6.0
- See Also:
- if this mime type has a wildcard type,
and the other does not, then this method returns
-
valueOf
Parse the given String value into aMimeType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.- See Also:
-