Class ContentType
java.lang.Object
uk.ac.starlink.util.ContentType
Represents a Content Type (MIME type) string.
Most of the work is done by the {link #parseContentType} factory method.
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");
- Since:
- 17 Nov 2017
- Author:
- Mark Taylor
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionContentType(String type, String subtype) Constructs a ContentType from type and subtype strings.Constructs a ContentType from its constituent parts. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetParameter(String paramName) Returns the value of a parameter of this content type.Returns the parameter name/value pairs of this content type.Returns the Subtype part of this content type.getType()Returns the Type part of this content type.inthashCode()static voidParses a single content-type string supplied on the command line, and prints a representation of the parsed form on standard output.booleanIndicates whether the type and subtype match a given pair.static ContentTypeparseContentType(String txt) Parses a Content-Type (MIME type) string in accordance with the syntax rules in RFC2045.toString()
-
Constructor Details
-
ContentType
-
ContentType
Constructs a ContentType from its constituent parts. Case is normalised (to lower case) for the case-insensitive parts, that is type, subtype and parameter names.- Parameters:
type- type partsubtype- subtype partparams- map of parameters
-
-
Method Details
-
getType
-
getSubtype
-
getParameters
-
matches
-
getParameter
-
hashCode
-
equals
-
toString
-
parseContentType
Parses a Content-Type (MIME type) string in accordance with the syntax rules in RFC2045. Such strings look something like "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.
- Parameters:
txt- content-type string of the approximate formtype/subtype(;param=value)*- Returns:
- ContentType object if
txtcan be parsed, otherwise null - See Also:
-
main
Parses a single content-type string supplied on the command line, and prints a representation of the parsed form on standard output.
-