A class that implements a Parser for RFC-6838 MimeTypes.
parse() is a convenience method around the underlyining parser-combinator parsers that this parser in implemented
on, providing an easy text in, optional mime out interface, where a secuess results in a MimeType instance, and a
failure results in Optional.empty().
example uses are:
- MimeTypeParser.parse("application/json")
- MimeTypeParser.parse("application/vnd.nike.runningcoach-v3.1+json; charset=UTF-8")
Because additional detail in how the mimetype was parsed may be desired, all of the constituent parsers are also
made public, allowing a developer compose or/or alter mimetype parsing, or compose exiting mimetype parsing into even
more sophistcated parsers, for example, RFC-2616 14.1 Accept headers, where mimetypes are combined with optional
quality rates.
e.g. Accept: text/*;q=0.3, text/html;q=0.7, text/html;level=1, text/html;level=2;q=0.4
This parser is implemented using the following from RFC-6838:
4.2. Naming Requirements
All registered media types MUST be assigned top-level type and
subtype names. The combination of these names serves to uniquely
identify the media type, and the subtype name facet (or the absence
of one) identifies the registration tree. Both top-level type and
subtype names are case-insensitive.
Type and subtype names MUST conform to the following ABNF:
type-name = restricted-name
subtype-name = restricted-name
restricted-name = restricted-name-first *126restricted-name-chars
restricted-name-first = ALPHA / DIGIT
restricted-name-chars = ALPHA / DIGIT / "!" / "#" / "$" / "&" / "-" / "^" / "_"
restricted-name-chars =/ "." ; Characters before first dot always specify a facet name
restricted-name-chars =/ "+" ; Characters after last plus always specify a structured syntax suffix
Provides a set of Parser instances for parsing a complete MimeType instance.
example use:
MimeParser.parse("application/vnd.nike.runningcoach-v3.1+json; charset=UTF-8")
results in an Optional, where in:
- the Type is Type. APPLICATION
- the SubType's Facet is Facet.VENDOR
- the SubType's Suffix is json
- the SubType's Name is nike.runningcoach-v3.1
- the Parameter Map contains one parameter if 'charset' with a value of 'UTF-8'