Package com.jalios.util
Class MimeType
- java.lang.Object
-
- com.jalios.util.MimeType
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<MimeType>
public class MimeType extends java.lang.Object implements java.lang.Comparable<MimeType>, java.io.Serializable
Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in other Internet protocols including HTTP.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMimeType.SpecificityComparator<T extends MimeType>
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringWILDCARD_TYPE
-
Constructor Summary
Constructors Constructor Description MimeType(MimeType other, java.util.Map<java.lang.String,java.lang.String> parameters)Copy-constructor that copies the type and subtype of the givenMimeType, and allows for different parameter.MimeType(java.lang.String type)Create a newMimeTypefor the given primary type.MimeType(java.lang.String type, java.lang.String subtype)Create a newMimeTypefor the given primary type and subtype.MimeType(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charSet)Create a newMimeTypefor the given type, subtype, and character set.MimeType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Create a newMimeTypefor the given type, subtype, and parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendTo(java.lang.StringBuilder builder)protected voidcheckParameters(java.lang.String attribute, java.lang.String value)intcompareTo(MimeType other)Compares thisMediaTypeto another alphabetically.booleanequals(java.lang.Object other)java.nio.charset.CharsetgetCharSet()Return the character set, as indicated by acharsetparameter, if any.java.lang.StringgetParameter(java.lang.String name)Return a generic parameter value, given a parameter name.java.util.Map<java.lang.String,java.lang.String>getParameters()Return all generic parameter values.java.lang.StringgetSubtype()Return the subtype.java.lang.StringgetType()Return the primary type.inthashCode()booleanincludes(MimeType other)Indicate whether thisMediaTypeincludes the given media type.booleanisCompatibleWith(MimeType other)Indicate whether thisMediaTypeis compatible with the given media type.booleanisConcrete()Indicates whether this media type is concrete, i.e.booleanisWildcardSubtype()Indicates whether the subtype is the wildcard character*or the wildcard character followed by a suffix (e.g.booleanisWildcardType()Indicates whether the type is the wildcard character*or not.static MimeTypeparseMimeType(java.lang.String mimeType)Parse the given String into a singleMimeType.java.lang.StringtoString()protected java.lang.Stringunquote(java.lang.String s)static MimeTypevalueOf(java.lang.String value)Parse the given String value into aMimeTypeobject, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService}.
-
-
-
Field Detail
-
WILDCARD_TYPE
protected static final java.lang.String WILDCARD_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MimeType
public MimeType(java.lang.String type)
Create a newMimeTypefor the given primary type.The subtype is set to
"*", and the parameters are empty.- Parameters:
type- the primary type- Throws:
java.lang.IllegalArgumentException- if any of the parameters contains illegal characters
-
MimeType
public MimeType(java.lang.String type, java.lang.String subtype)Create a newMimeTypefor the given primary type and subtype.The parameters are empty.
- Parameters:
type- the primary typesubtype- the subtype- Throws:
java.lang.IllegalArgumentException- if any of the parameters contains illegal characters
-
MimeType
public MimeType(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charSet)Create a newMimeTypefor the given type, subtype, and character set.- Parameters:
type- the primary typesubtype- the subtypecharSet- the character set- Throws:
java.lang.IllegalArgumentException- if any of the parameters contains illegal characters
-
MimeType
public MimeType(MimeType other, java.util.Map<java.lang.String,java.lang.String> parameters)
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:
java.lang.IllegalArgumentException- if any of the parameters contains illegal characters
-
MimeType
public MimeType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Create a newMimeTypefor the given type, subtype, and parameters.- Parameters:
type- the primary typesubtype- the subtypeparameters- the parameters, may benull- Throws:
java.lang.IllegalArgumentException- if any of the parameters contains illegal characters
-
-
Method Detail
-
checkParameters
protected void checkParameters(java.lang.String attribute, java.lang.String value)
-
unquote
protected java.lang.String unquote(java.lang.String s)
-
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 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
public java.lang.String getType()
Return the primary type.
-
getSubtype
public java.lang.String getSubtype()
Return the subtype.
-
getCharSet
public java.nio.charset.Charset getCharSet()
Return the character set, as indicated by acharsetparameter, if any.- Returns:
- the character set, or
nullif not available
-
getParameter
public java.lang.String getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name.- Parameters:
name- the parameter name- Returns:
- the parameter value, or
nullif not present
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Return all generic parameter values.- Returns:
- a read-only map (possibly empty, never
null)
-
includes
public boolean includes(MimeType other)
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
public boolean isCompatibleWith(MimeType other)
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.jalios.util.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
-
compareTo
public int compareTo(MimeType other)
Compares thisMediaTypeto another alphabetically.- Specified by:
compareToin interfacejava.lang.Comparable<MimeType>- Parameters:
other- media type to compare to
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
appendTo
protected void appendTo(java.lang.StringBuilder builder)
-
valueOf
public static MimeType valueOf(java.lang.String value)
Parse the given String value into aMimeTypeobject, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService}.
-
parseMimeType
public static MimeType parseMimeType(java.lang.String mimeType)
Parse the given String into a singleMimeType.- Parameters:
mimeType- the string to parse- Returns:
- the mime type
-
-