public final class ContentType
extends java.lang.Object
At present this class doesn't support multiple parameters with the same name. Each occurrence of a key will override any previous occurrences of the same key.
ContentTypes are immutable. To derive a new ContentType with different parameters from an existing one use
ContentType(ContentType, Parameter...).
Note that equals(Object) returns true for two ContentTypes if mainType and subType equal. Parameters are not taken
into account. Use same(ContentType) to take parameters into account when comparing two ContentTypes.
| Modifier and Type | Class and Description |
|---|---|
static class |
ContentType.Parameter
A content type parameter as defined in RFC 2045 Section 5.
|
| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
mainType
The main type of the content type.
|
java.lang.String |
subType
The sub-type of the content type.
|
java.lang.String |
type
The content type as
maintype/subtype. |
| Constructor and Description |
|---|
ContentType(ContentType contentType,
ContentType.Parameter... params)
Clone constructor that adds/overrides
ContentType.Parameters. |
ContentType(java.lang.String contentType)
Create a new
ContentType from a content type string. |
ContentType(java.lang.String contentType,
ContentType.Parameter... params)
Creates a new
ContentType object from the given string representation, while adding or overriding ContentType.Parameters. |
| Modifier and Type | Method and Description |
|---|---|
static ContentType.Parameter |
CharSet(java.lang.String charset) |
boolean |
equals(java.lang.Object obj) |
boolean |
equalsAny(ContentType... contentTypes)
Returns whether this
ContentType equals any of the given content types. |
java.lang.String |
getCharset()
Returns the value of the charset parameter or
null if there is no charset parameter. |
java.lang.String |
getCharset(java.lang.String defaultCharset)
Returns the value of the charset parameter or
default if there is no charset parameter. |
int |
hashCode() |
boolean |
isAnySubType() |
boolean |
isAnyType() |
boolean |
matches(ContentType other)
Checks if another content type matches this content type.
|
ContentType.Parameter |
param(java.lang.String key)
Return the parameter value for a specific key.
|
boolean |
same(ContentType other)
Indicates whether another
ContentType is the same as this one. |
java.lang.String |
toString() |
public final java.lang.String type
maintype/subtype.public final java.lang.String mainType
public final java.lang.String subType
public ContentType(java.lang.String contentType)
ContentType from a content type string. If contentType is null type, mainType and subType
will be null.contentType - The content type string to parse.public ContentType(java.lang.String contentType,
ContentType.Parameter... params)
ContentType object from the given string representation, while adding or overriding ContentType.Parameters.contentType - A string representation of a content-type.params - ContentType.Parameters to add or override.public ContentType(ContentType contentType, ContentType.Parameter... params)
ContentType.Parameters.contentType - The original content type.params - The ContentType.Parameters to add or override.public ContentType.Parameter param(java.lang.String key)
key - The key of the parameter.String.public java.lang.String getCharset()
null if there is no charset parameter.String containing the charset or null.public java.lang.String getCharset(java.lang.String defaultCharset)
default if there is no charset parameter.String containing the charset.public boolean isAnySubType()
public boolean isAnyType()
public java.lang.String toString()
toString in class java.lang.Objectpublic static ContentType.Parameter CharSet(java.lang.String charset)
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic boolean equalsAny(ContentType... contentTypes)
ContentType equals any of the given content types.contentTypes - Non-empty list of other ContentTypes.true if this equals one of the given ContentTypes, false otherwise.public boolean same(ContentType other)
ContentType is the same as this one. In contrast to equals(Object) this also takes any parameters into
account.other - The other ContentType.true if maintype, subtype and parameters of both content-types equal.public boolean matches(ContentType other)
equals(Object) returns it, except that this method honors place
holders in this instance. Parameters are not taken into account.other - The ContentType to match.ContentType matches this content type.