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 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, Sam Brannen
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCopy-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.Create a newMimeTypefor the given primary type.Create a newMimeTypefor the given primary type and subtype.Create a newMimeTypefor the given type, subtype, and character set.Create a newMimeTypefor the given type, subtype, and parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendTo(StringBuilder builder) protected voidcheckParameters(String attribute, String value) intCompares thisMediaTypeto another alphabetically.booleanReturn the character set, as indicated by acharsetparameter, if any.getParameter(String name) Return a generic parameter value, given a parameter name.Return all generic parameter values.Return the subtype.getType()Return the primary type.inthashCode()booleanIndicate whether thisMediaTypeincludes the given media type.booleanisCompatibleWith(MimeType other) Indicate whether thisMediaTypeis compatible with the given media type.booleanIndicates whether this media type is concrete, i.e. whether neither the type nor the subtype is a wildcard character*.booleanIndicates whether the subtype is the wildcard character*or the wildcard character followed by a suffix (e.g.booleanIndicates whether the type is the wildcard character*or not.toString()protected Stringstatic MimeTypeParse the given String value into aMimeTypeobject, with this method name following the 'valueOf' naming convention (as supported byorg.springframework.core.convert.ConversionService.
-
Field Details
-
WILDCARD_TYPE
- See Also:
-
-
Constructor Details
-
MimeType
Create a newMimeTypefor 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 newMimeTypefor 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 newMimeTypefor 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 media typecharset- 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 media typeparameters- the parameters, may benull- Throws:
IllegalArgumentException- if any of the parameters contains illegal characters
-
MimeType
Create a newMimeTypefor 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
-
-
Method Details
-
checkParameters
-
unquote
-
isWildcardType
public boolean isWildcardType()Indicates whether the type is the wildcard character*or not.- Returns:
- return true if this type is a wildcard
-
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 media type is concrete, i.e. whether neither the type nor the subtype is a wildcard character*.- Returns:
- whether this media type is concrete
-
getType
Return the primary type.- Returns:
- return the type
-
getSubtype
Return the subtype.- Returns:
- return the subtype
-
getCharset
Return the character set, as indicated by acharsetparameter, if any.- Returns:
- the character set, or
nullif 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
nullif not present
-
getParameters
Return all generic parameter values.- Returns:
- a read-only map (possibly empty, never
null)
-
includes
Indicate whether thisMediaTypeincludes the given media type.For instance,
text/*includestext/plainandtext/html, andapplication/*+xmlincludesapplication/soap+xml, etc. This method is not symmetric.- Parameters:
other- the reference media type with which to compare- Returns:
trueif this media type includes the given media type;falseotherwise
-
isCompatibleWith
Indicate whether thisMediaTypeis compatible with the given media type.For instance,
text/*is compatible withtext/plain,text/html, and vice versa. In effect, this method is similar toincludes(com.okta.commons.http.MimeType), except that it is symmetric.- Parameters:
other- the reference media type with which to compare- Returns:
trueif this media type is compatible with the given media type;falseotherwise
-
equals
-
hashCode
public int hashCode() -
toString
-
appendTo
-
compareTo
Compares thisMediaTypeto another alphabetically.- Specified by:
compareToin interfaceComparable<MimeType>- Parameters:
other- media type to compare to- See Also:
-
valueOf
Parse the given String value into aMimeTypeobject, with this method name following the 'valueOf' naming convention (as supported byorg.springframework.core.convert.ConversionService.- Parameters:
value- string to parse- Returns:
- MimeType base on
value - See Also:
-