public class ContentType extends Object
This takes care of things like optional whitespace and case folding,
so for instance if ctypeTxt
has the value
APPLICATION / X-VOTABLE+XML ; content=datalink; CHARSET="iso\-8859\-1"then
ContentType ctype = CointentType.parse(ctypeTxt); assert ctype.matches("application", "x-votable+xml"); assert ctype.getParameter("charset").equals("iso-8859-1");
Constructor and Description |
---|
ContentType(String type,
String subtype)
Constructs a ContentType from type and subtype strings.
|
ContentType(String type,
String subtype,
Map<String,String> params)
Constructs a ContentType from its constituent parts.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
String |
getParameter(String paramName)
Returns the value of a parameter of this content type.
|
Map<String,String> |
getParameters()
Returns the parameter name/value pairs of this content type.
|
String |
getSubtype()
Returns the Subtype part of this content type.
|
String |
getType()
Returns the Type part of this content type.
|
int |
hashCode() |
static void |
main(String[] args)
Parses a single content-type string supplied on the command line,
and prints a representation of the parsed form on standard output.
|
boolean |
matches(String type,
String subtype)
Indicates whether the type and subtype match a given pair.
|
static ContentType |
parseContentType(String txt)
Parses a Content-Type (MIME type) string in accordance with
the syntax rules in RFC2045.
|
String |
toString() |
public ContentType(String type, String subtype)
type
- type partsubtype
- subtype partpublic ContentType(String type, String subtype, Map<String,String> params)
type
- type partsubtype
- subtype partparams
- map of parameterspublic String getType()
public String getSubtype()
public Map<String,String> getParameters()
public boolean matches(String type, String subtype)
type
- required type part (case-insensitive)subtype
- required subtype part (case-insensitive)public String getParameter(String paramName)
paramName
- parameter name (case-insensitive)public static ContentType parseContentType(String txt)
type/subtype[;p1=v1;p2=v2...]
".
It may not be completely bulletproof, but should do a fairly
good job of the parse. However, it makes no attempt to
restrict the type or subtype to IANA-approved values,
and it may parse some strings which are not strictly legal.
Null is returned if the string cannot be parsed.
txt
- content-type string of the approximate form
type/subtype(;param=value)*
txt
can be parsed,
otherwise nullpublic static void main(String[] args)
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.