public class MimeType extends Object implements Comparable<MimeType>, Serializable
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,
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. |
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 sufiix (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 "*", parameters empty.
type
- the primary typeIllegalArgumentException
- if any of the parameters contain 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 contain 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 contain 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 contain 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 contain illegal characterspublic boolean isWildcardType()
*
or not.public boolean isWildcardSubtype()
*
or the wildcard character followed by a sufiix (e.g.
*+xml
), or not.*
public boolean isConcrete()
*
.public String getType()
public String getSubtype()
public Charset getCharSet()
charset
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
otherwisepublic int compareTo(MimeType other)
MediaType
to another alphabetically.compareTo
in interface Comparable<MimeType>
other
- media type to compare toMimeTypeUtils.sortBySpecificity(List)
protected void appendTo(StringBuilder builder)
public static MimeType valueOf(String value)
MimeType
object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService
.MimeTypeUtils.parseMimeType(String)