public final class ContentType extends Object
The relevant productions from RFC 2045 and RFC 822 are:
content := "Content-Type" ":" type "/" subtype *(";" parameter) parameter := attribute "=" value attribute := token value := token / quoted-string token := 1*<any (US-ASCII) CHAR except SPACE, CTLs, or tspecials> tspecials := "(" / ")" / "<" / ">" / "@" / "," / ";" / ":" / "\" / <"> / "/" / "[" / "]" / "?" / "=" quoted-string := <"> *(qtext/quoted-pair) <"> qtext := <any CHAR excepting <">, "\" & CR, and including linear-white-space> quoted-pair := "\" CHAR
This class is similar to MimeType
and JavaMail's ContentType
class, but the
following differences exist:
MimeType
. It will
accept content types that are not strictly valid, but that are commonly found. E.g. it will
accept content types with an extra semicolon at the end.
MediaType
object) and a content type, which is defined by a
media type and a set of parameters.
Another reason for the existence of this class is to avoid a dependency on JavaMail.
Note that this class doesn't override Object.equals(Object)
because there is no
meaningful way to compare content types with parameters.
Constructor and Description |
---|
ContentType(MediaType mediaType,
String[] parameters)
Constructor.
|
ContentType(String type)
Constructor that parses a Content-Type header value.
|
Modifier and Type | Method and Description |
---|---|
MediaType |
getMediaType()
Get the media type this content type refers to.
|
String |
getParameter(String name)
Get the specified parameter value.
|
String |
toString()
Create a string representation of this content type suitable as the value for a
Content-Type header as specified by RFC 2045.
|
public ContentType(MediaType mediaType, String[] parameters)
mediaType
- the media typeparameters
- an array specifying the parameters as name/value pairs (with even entries
representing the parameter names, and odd entries the corresponding values)public ContentType(String type) throws ParseException
type
- the value of the Content-Type header conforming to RFC 2045ParseException
- if the value is invalid and could not be parsedpublic MediaType getMediaType()
public String getParameter(String name)
name
- the parameter namenull
if no parameter with the given name was
foundpublic String toString()
Copyright © The Apache Software Foundation. All Rights Reserved.