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 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
.
MimeTypeUtils
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
MimeType.SpecificityComparator<T extends MimeType>
Comparator to sort
MimeTypes in order of specificity. |
Modifier and Type | Field and Description |
---|---|
protected static String |
WILDCARD_TYPE |
Modifier | Constructor and Description |
---|---|
protected |
MimeType(MimeType other)
Copy-constructor that copies the type, subtype and parameters of the given
MimeType ,
skipping checks performed in other constructors. |
|
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 parameter,
String value) |
int |
compareTo(MimeType other)
Compares this MIME Type to another alphabetically.
|
boolean |
equals(Object other) |
boolean |
equalsTypeAndSubtype(MimeType other)
Similar to
equals(Object) but based on the type and subtype
only, i.e. |
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 |
getSubtypeSuffix()
Return the subtype suffix as defined in RFC 6839.
|
String |
getType()
Return the primary type.
|
int |
hashCode() |
boolean |
includes(MimeType other)
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 |
isConcrete()
Indicates whether this MIME Type is concrete, i.e.
|
boolean |
isPresentIn(Collection<? extends MimeType> mimeTypes)
Unlike
Collection.contains(Object) which relies on
equals(Object) , this method only checks the type and the
subtype, but otherwise ignores parameters. |
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 MimeTypecharset
- the character setIllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(MimeType other, @Nullable Map<String,String> parameters)
MimeType
,
and allows for different parameter.other
- the other MimeTypeparameters
- the parameters (may be null
)IllegalArgumentException
- if any of the parameters contains illegal characterspublic MimeType(String type, String subtype, @Nullable 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 charactersprotected MimeType(MimeType other)
MimeType
,
skipping checks performed in other constructors.other
- the other MimeTypepublic 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()
@Nullable public String getSubtypeSuffix()
@Nullable public Charset getCharset()
charset
parameter, if any.null
if not available@Nullable public String getParameter(String name)
name
- the parameter namenull
if not presentpublic Map<String,String> getParameters()
null
)public boolean includes(@Nullable MimeType other)
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 MIME Type with which to comparetrue
if this MIME Type includes the given MIME Type;
false
otherwisepublic boolean isCompatibleWith(@Nullable MimeType other)
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 MIME Type with which to comparetrue
if this MIME Type is compatible with the given MIME Type;
false
otherwisepublic boolean equalsTypeAndSubtype(@Nullable MimeType other)
equals(Object)
but based on the type and subtype
only, i.e. ignoring parameters.other
- the other mime type to compare topublic boolean isPresentIn(Collection<? extends MimeType> mimeTypes)
Collection.contains(Object)
which relies on
equals(Object)
, this method only checks the type and the
subtype, but otherwise ignores parameters.mimeTypes
- the list of mime types to perform the check againstprotected void appendTo(StringBuilder builder)
public int compareTo(MimeType other)
compareTo
in interface Comparable<MimeType>
other
- the MIME 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)