Class MimeType
- java.lang.Object
- org.springframework.util.MimeType
- All Implemented Interfaces:
Serializable
,Comparable<MimeType>
- Direct Known Subclasses:
MediaType
public class MimeType extends Object implements Comparable<MimeType>, Serializable
Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in other Internet protocols including HTTP.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 thespring-web
module.Consists of a type and a subtype. Also has functionality to parse MIME Type values from a
String
usingvalueOf(String)
. For more parsing options seeMimeTypeUtils
.- Since:
- 4.0
- Author:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sam Brannen
- See Also:
MimeTypeUtils
, Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MimeType.SpecificityComparator<T extends MimeType>
Field Summary
Fields Modifier and Type Field Description protected static String
WILDCARD_TYPE
Constructor Summary
Constructors Constructor Description MimeType(String type)
Create a newMimeType
for the given primary type.MimeType(String type, String subtype)
Create a newMimeType
for the given primary type and subtype.MimeType(String type, String subtype, Charset charset)
Create a newMimeType
for the given type, subtype, and character set.MimeType(String type, String subtype, Map<String,String> parameters)
Create a newMimeType
for the given type, subtype, and parameters.MimeType(MimeType other, Charset charset)
Copy-constructor that copies the type, subtype, parameters of the givenMimeType
, 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 givenMimeType
, and allows for different parameter.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
appendTo(StringBuilder builder)
protected void
checkParameters(String attribute, String value)
int
compareTo(MimeType other)
Compares this MIME Type to another alphabetically.boolean
equals(Object other)
Charset
getCharset()
Return the character set, as indicated by acharset
parameter, if any.Charset
getCharSet()
Deprecated.as of Spring 4.3, in favor ofgetCharset()
with its name aligned with the Java return type nameString
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 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
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 aMimeType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.
Field Detail
WILDCARD_TYPE
protected static final String WILDCARD_TYPE
- See Also:
- Constant Field Values
Constructor Detail
MimeType
public MimeType(String type)
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
public MimeType(String type, String subtype)
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
public MimeType(String type, String subtype, Charset charset)
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
public MimeType(MimeType other, Charset charset)
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
public MimeType(MimeType other, Map<String,String> parameters)
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
public MimeType(String type, String subtype, Map<String,String> parameters)
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
Method Detail
checkParameters
protected void checkParameters(String attribute, String value)
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
getSubtype
public String getSubtype()
Return the subtype.
getCharset
public Charset getCharset()
Return the character set, as indicated by acharset
parameter, if any.- Returns:
- the character set, or
null
if not available - Since:
- 4.3
getCharSet
@Deprecated public Charset getCharSet()
Deprecated.as of Spring 4.3, in favor ofgetCharset()
with its name aligned with the Java return type nameReturn the character set, as indicated by acharset
parameter, if any.- Returns:
- the character set, or
null
if not available
getParameter
public String getParameter(String name)
Return a generic parameter value, given a parameter name.- Parameters:
name
- the parameter name- Returns:
- the parameter value, or
null
if not present
getParameters
public Map<String,String> getParameters()
Return all generic parameter values.- Returns:
- a read-only map (possibly empty, never
null
)
includes
public boolean includes(MimeType other)
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
public boolean isCompatibleWith(MimeType other)
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
appendTo
protected void appendTo(StringBuilder builder)
compareTo
public int compareTo(MimeType other)
Compares this MIME Type to another alphabetically.- Specified by:
compareTo
in interfaceComparable<MimeType>
- Parameters:
other
- the MIME Type to compare to- See Also:
MimeTypeUtils.sortBySpecificity(List)
valueOf
public static MimeType valueOf(String value)
Parse the given String value into aMimeType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.- See Also:
MimeTypeUtils.parseMimeType(String)