public class MimeType extends Object implements Comparable<MimeType>, Serializable
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
.
MimeTypeUtils
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
MimeType.SpecificityComparator<T extends MimeType> |
Modifier and Type | Field and Description |
---|---|
protected static String |
WILDCARD_TYPE |
Constructor and Description |
---|
MimeType(MimeType other,
Charset charset)
Copy-constructor that copies the type, subtype, parameters of the given
MimeType ,
and allows to set the specified character set. |
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. |
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. |
Charset |
getCharSet()
Deprecated.
as of Spring 4.3, in favor of
getCharset() with its name
aligned with the Java return type name |
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
* or the wildcard character followed by a suffix
(e.g. |
boolean |
isWildcardType()
Indicates whether the type is the wildcard character
* 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 . |
protected static final String WILDCARD_TYPE
public MimeType(String type)
MimeType
for the given primary type.
The subtype is set to "*"
,
and the parameters are empty.
type
- the primary typeIllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(String type, String subtype)
MimeType
for the given primary type and subtype.
The parameters are empty.
type
- the primary typesubtype
- the subtypeIllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(String type, String subtype, Charset charset)
MimeType
for the given type, subtype, and character set.type
- the primary typesubtype
- the subtypecharset
- the character setIllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(MimeType other, Charset charset)
MimeType
,
and allows to set the specified character set.other
- the other media typecharset
- the character setIllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(MimeType other, Map<String,String> parameters)
MimeType
,
and allows for different parameter.other
- the other media typeparameters
- the parameters, may be null
IllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(String type, String subtype, Map<String,String> parameters)
MimeType
for the given type, subtype, and parameters.type
- the primary typesubtype
- the subtypeparameters
- the parameters, may be null
IllegalArgumentException
- if any of the parameters contains illegal characterspublic boolean isWildcardType()
*
or not.public boolean isWildcardSubtype()
*
or the wildcard character followed by a suffix
(e.g. *+xml
).public boolean isConcrete()
*
.public String getType()
public String getSubtype()
public Charset getCharset()
charset
parameter, if any.null
if not available@Deprecated public Charset getCharSet()
getCharset()
with its name
aligned with the Java return type namecharset
parameter, if any.null
if not availablepublic String getParameter(String name)
name
- the parameter namenull
if not presentpublic Map<String,String> getParameters()
null
)public boolean includes(MimeType other)
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.
other
- the reference media type with which to comparetrue
if this media type includes the given media type;
false
otherwisepublic boolean isCompatibleWith(MimeType other)
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.
other
- the reference media type with which to comparetrue
if this media type is compatible with the given media type;
false
otherwiseprotected void appendTo(StringBuilder builder)
public int compareTo(MimeType other)
MediaType
to another alphabetically.compareTo
in interface Comparable<MimeType>
other
- media type to compare toMimeTypeUtils.sortBySpecificity(List)
public static MimeType valueOf(String value)
MimeType
object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService
.MimeTypeUtils.parseMimeType(String)