Package uk.ac.starlink.util
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 TypeMethodDescriptionboolean
getParameter
(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.int
hashCode()
static void
Parses a single content-type string supplied on the command line, and prints a representation of the parsed form on standard output.boolean
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.toString()
-
Constructor Details
-
ContentType
Constructs a ContentType from type and subtype strings. Case is normalised (to lower case).- Parameters:
type
- type partsubtype
- subtype part
-
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
Returns the Type part of this content type.- Returns:
- type
-
getSubtype
Returns the Subtype part of this content type.- Returns:
- subtype
-
getParameters
Returns the parameter name/value pairs of this content type. The parameter names (keys of the returned map) will always be in lower case.- Returns:
- name/value pairs as an ordered map
-
matches
Indicates whether the type and subtype match a given pair.- Parameters:
type
- required type part (case-insensitive)subtype
- required subtype part (case-insensitive)- Returns:
- true iff type and subtype match those of this content-type
-
getParameter
Returns the value of a parameter of this content type.- Parameters:
paramName
- parameter name (case-insensitive)- Returns:
- parameter value, or null if no such parameter
-
hashCode
public int 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
txt
can 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.
-