Class MediaType
java.lang.Object
com.github.mizosoft.methanol.MediaType
A MIME
type. The text representation of this class can be used as the value
of the
Content-Type HTTP header.
A MediaType also defines a media range. A media range has
either both wildcard type and subtype, both concrete type and subtype, or a concrete type and a
wildcard subtype (but not a wildcard type and a concrete subtype), with the character *
denoting a wildcard. Inclusion in media ranges can be tested using any of includes(MediaType) or isCompatibleWith(MediaType), with the latter being symmetric
among operands.
Case-insensitive attributes such as the type, subtype, parameter names or the value of the charset parameter are converted into lower-case.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MediaType*/*static final MediaTypeapplication/*static final MediaTypeapplication/x-www-form-urlencodedstatic final MediaTypeapplication/jsonstatic final MediaTypeapplication/octet-streamstatic final MediaTypeapplication/x-protobufstatic final MediaTypeapplication/xhtml+xmlstatic final MediaTypeapplication/xmlstatic final MediaTypeimage/*static final MediaTypeimage/gifstatic final MediaTypeimage/jpegstatic final MediaTypeimage/pngstatic final MediaTypetext/*static final MediaTypetext/htmlstatic final MediaTypetext/markdownstatic final MediaTypetext/plainstatic final MediaTypetext/xml -
Method Summary
Modifier and TypeMethodDescriptioncharset()Returns anOptionalrepresenting the value of the charset parameter.charsetOrDefault(Charset defaultCharset) Returns either the value of the charset parameter or the given default charset if no such parameter exists or if the charset has no support in this JVM.Equivalent to callingcharsetOrDefault(StandardCharsets.UTF_8).booleanTests the given object for equality with this instance.inthashCode()Returns a hashcode for this media type.booleanReturnstrueif this media type is*/*or if it has a wildcard subtype.booleanReturns whether this media type includes the given one.booleanisCompatibleWith(MediaType other) Returns whether this media type is compatible with the given one.static MediaTypeReturns a newMediaTypewith the given type and subtype.static MediaTypeReturns a newMediaTypewith the given type, subtype and parameters.Returns an immutable map representing the parameters.static MediaTypeParses the given string into aMediaTypeinstance.subtype()Returns the subtype.toString()Returns a text representation of this media type that is compatible with the value of theContent-Typeheader.type()Returns the general type.withCharset(Charset charset) Returns a newMediaTypewith this instance's type, subtype and parameters but with the name of the given charset as the value of the charset parameter.withParameter(String name, String value) Returns a newMediaTypewith this instance's type, subtype and parameters but with the value of the parameter specified by the given name set to the given value.withParameters(Map<String, String> parameters) Returns a newMediaTypewith this instance's type, subtype and parameters but with each of the given parameters' names set to their corresponding values.
-
Field Details
-
ANY
*/* -
APPLICATION_ANY
application/* -
IMAGE_ANY
image/* -
TEXT_ANY
text/* -
APPLICATION_FORM_URLENCODED
application/x-www-form-urlencoded -
APPLICATION_JSON
application/json -
APPLICATION_OCTET_STREAM
application/octet-stream -
APPLICATION_XHTML_XML
application/xhtml+xml -
APPLICATION_XML
application/xml -
APPLICATION_X_PROTOBUF
application/x-protobuf -
IMAGE_GIF
image/gif -
IMAGE_JPEG
image/jpeg -
IMAGE_PNG
image/png -
TEXT_HTML
text/html -
TEXT_MARKDOWN
text/markdown -
TEXT_PLAIN
text/plain -
TEXT_XML
text/xml
-
-
Method Details
-
type
Returns the general type. -
subtype
Returns the subtype. -
parameters
-
charset
Returns anOptionalrepresenting the value of the charset parameter. An emptyOptionalis returned if no such parameter exists.- Throws:
IllegalCharsetNameException- if a charset parameter exists the value of which is invalidUnsupportedCharsetException- if a charset parameter exists the value of which is not supported in this JVM
-
charsetOrDefault
Returns either the value of the charset parameter or the given default charset if no such parameter exists or if the charset has no support in this JVM.- Throws:
IllegalCharsetNameException- if a charset parameter exists the value of which is invalid
-
charsetOrUtf8
Equivalent to callingcharsetOrDefault(StandardCharsets.UTF_8). -
hasWildcard
public boolean hasWildcard()Returnstrueif this media type is*/*or if it has a wildcard subtype. -
includes
Returns whether this media type includes the given one. A media type includes the other if the former's parameters is a subset of the latter's and either the former is awildcard typethat includes the latter or both have equal concrete type and subtype. -
isCompatibleWith
-
withCharset
-
withParameter
Returns a newMediaTypewith this instance's type, subtype and parameters but with the value of the parameter specified by the given name set to the given value.- Throws:
IllegalArgumentException- if the given name or value is invalid
-
withParameters
Returns a newMediaTypewith this instance's type, subtype and parameters but with each of the given parameters' names set to their corresponding values.- Throws:
IllegalArgumentException- if any of the given parameters is invalid
-
equals
-
hashCode
-
toString
-
of
Returns a newMediaTypewith the given type and subtype.- Throws:
IllegalArgumentException- if the given type or subtype is invalid
-
of
-
parse
Parses the given string into aMediaTypeinstance.- Throws:
IllegalArgumentException- if the given string is an invalid media type
-