- All Implemented Interfaces:
AcceptPredicate<MediaType>
,Predicate<MediaType>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A fluent API builder to create instances ofMediaType
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MediaType
AMediaType
constant representingapplication/atom+xml
media type.static final MediaType
AMediaType
constant representingapplication/x-www-form-urlencoded
media type.static final MediaType
AMediaType
constant representingapplication/javascript
media type.static final MediaType
AMediaType
constant representingapplication/json
media type.static final MediaType
AMediaType
constant representingapplication/octet-stream
media type.static final MediaType
AMediaType
constant representing OpenAPI json.static final MediaType
AMediaType
constant representing OpenAPI yaml.static final MediaType
AMediaType
constant representing theapplication/openmetrics-text
media type.static final MediaType
AMediaType
constant representingapplication/stream+json
media type.static final MediaType
AMediaType
constant representingapplication/svg+xml
media type.static final MediaType
AMediaType
constant representingapplication/x-ndjson
media type.static final MediaType
AMediaType
constant representing "x" YAML as application.static final MediaType
AMediaType
constant representingapplication/xhtml+xml
media type.static final MediaType
AMediaType
constant representingapplication/xml
media type.static final MediaType
AMediaType
constant representing pseudo-registered YAML.static final String
The media type "charset" parameter name.Predicate to test ifMediaType
istext/event-stream
without any parameter or with parameter "element-type".static final MediaType
AMediaType
constant representingmultipart/form-data
media type.static final MediaType
AMediaType
constant representingtext/event-stream
media type.static final MediaType
AMediaType
constant representingtext/html
media type.static final MediaType
AMediaType
constant representingtext/plain
media type.static final MediaType
AMediaType
constant representing "x" YAML as text.static final MediaType
AMediaType
constant representingtext/xml
media type.static final MediaType
AMediaType
constant representing pseudo-registered YAML as text.static final MediaType
AMediaType
constant representing wildcard media type.Fields inherited from interface io.helidon.common.http.AcceptPredicate
QUALITY_FACTOR_PARAMETER, WILDCARD_VALUE
-
Method Summary
Modifier and TypeMethodDescriptionstatic MediaType.Builder
builder()
A fluent API builder for creating customized Media type instances.charset()
GetsOptional
value of charset parameter.static MediaType
Creates a new instance ofMediaType
with the supplied type and subtype.boolean
Comparesobj
to this media type to see if they are the same by comparing type, subtype and parameters.int
hashCode()
Generate a hash code from the type, subtype and parameters.boolean
Tests if this media type has provided Structured Syntaxsuffix
(RFC 6839).boolean
Checks if the subtype is a wildcard.boolean
Checks if the primary type is a wildcard.Getter for a read-only parameter map.static MediaType
Parses a media type from its string representation.static MediaType
parseRelaxed
(String input) Parses a media type from its string representation in relaxed mode.double
Gets quality factor parameter ("q") as a double value.subtype()
Getter for subtype.boolean
Check if this media type is compatible with another media type.toString()
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.type()
Getter for primary type.withCharset
(String charset) Create a newMediaType
instance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.Deprecated, for removal: This API element is subject to removal in a future version.will be removed in 4.x version.
-
Field Details
-
CHARSET_PARAMETER
The media type "charset" parameter name.- See Also:
-
WILDCARD
AMediaType
constant representing wildcard media type. -
APPLICATION_XML
AMediaType
constant representingapplication/xml
media type. -
APPLICATION_ATOM_XML
AMediaType
constant representingapplication/atom+xml
media type. -
APPLICATION_XHTML_XML
AMediaType
constant representingapplication/xhtml+xml
media type. -
APPLICATION_SVG_XML
AMediaType
constant representingapplication/svg+xml
media type. -
APPLICATION_JSON
AMediaType
constant representingapplication/json
media type. -
APPLICATION_STREAM_JSON
AMediaType
constant representingapplication/stream+json
media type. -
APPLICATION_FORM_URLENCODED
AMediaType
constant representingapplication/x-www-form-urlencoded
media type. -
MULTIPART_FORM_DATA
AMediaType
constant representingmultipart/form-data
media type. -
APPLICATION_OCTET_STREAM
AMediaType
constant representingapplication/octet-stream
media type. -
TEXT_PLAIN
AMediaType
constant representingtext/plain
media type. -
TEXT_XML
AMediaType
constant representingtext/xml
media type. -
TEXT_HTML
AMediaType
constant representingtext/html
media type. -
APPLICATION_OPENAPI_YAML
AMediaType
constant representing OpenAPI yaml.See https://github.com/opengeospatial/WFS_FES/issues/117#issuecomment-402188280
-
APPLICATION_OPENAPI_JSON
AMediaType
constant representing OpenAPI json. -
APPLICATION_X_YAML
AMediaType
constant representing "x" YAML as application. -
APPLICATION_YAML
AMediaType
constant representing pseudo-registered YAML. (It is not actually registered.) -
TEXT_X_YAML
AMediaType
constant representing "x" YAML as text. -
TEXT_YAML
AMediaType
constant representing pseudo-registered YAML as text. -
APPLICATION_JAVASCRIPT
AMediaType
constant representingapplication/javascript
media type. -
TEXT_EVENT_STREAM
AMediaType
constant representingtext/event-stream
media type. -
APPLICATION_X_NDJSON
AMediaType
constant representingapplication/x-ndjson
media type. -
APPLICATION_OPENMETRICS
AMediaType
constant representing theapplication/openmetrics-text
media type. -
XML_PREDICATE
-
JSON_PREDICATE
-
JSON_EVENT_STREAM_PREDICATE
Predicate to test ifMediaType
istext/event-stream
without any parameter or with parameter "element-type". This "element-type" has to be equal to "application/json".
-
-
Method Details
-
create
Creates a new instance ofMediaType
with the supplied type and subtype.- Parameters:
type
- the primary type,null
is equivalent toAcceptPredicate.WILDCARD_VALUE
subtype
- the subtype,null
is equivalent toAcceptPredicate.WILDCARD_VALUE
- Returns:
- a new media type for the specified type and subtype
-
parse
Parses a media type from its string representation.- Parameters:
input
- the input string representing a media type- Returns:
- parsed
MediaType
instance - Throws:
IllegalArgumentException
- if the input is not parsableNullPointerException
- if the input isnull
-
parseRelaxed
Parses a media type from its string representation in relaxed mode. Predefined incomplete media types are replaced with corresponding valid media types.- Parameters:
input
- the input string representing a media type- Returns:
- parsed
MediaType
instance - Throws:
IllegalArgumentException
- if the input is not parsableNullPointerException
- if the input isnull
-
builder
A fluent API builder for creating customized Media type instances.- Returns:
- a new builder
-
type
Getter for primary type.- Returns:
- value of primary type.
-
isWildcardType
public boolean isWildcardType()Checks if the primary type is a wildcard.- Returns:
- true if the primary type is a wildcard.
-
subtype
Getter for subtype.- Returns:
- value of subtype.
-
isWildcardSubtype
public boolean isWildcardSubtype()Checks if the subtype is a wildcard.- Returns:
- true if the subtype is a wildcard.
-
parameters
Getter for a read-only parameter map. Keys are case-insensitive.- Returns:
- an immutable map of parameters.
-
withCharset
Create a newMediaType
instance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter. -
withoutParameters
Deprecated, for removal: This API element is subject to removal in a future version.will be removed in 4.x version.Create a newMediaType
instance with the same type and subtype. All parameters are trimmed. If currentMediaType
instance does not contain parameters, the same instance is returned.- Returns:
MediaType
instance without parameters.
-
charset
GetsOptional
value of charset parameter.- Returns:
- Charset parameter.
-
qualityFactor
public double qualityFactor()Description copied from interface:AcceptPredicate
Gets quality factor parameter ("q") as a double value. If missing, then returns1.0
- Specified by:
qualityFactor
in interfaceAcceptPredicate<MediaType>
- Returns:
- Quality factor parameter.
-
test
Check if this media type is compatible with another media type. E.g. image/* is compatible with image/jpeg, image/png, etc. Media type parameters are ignored. The function is commutative. -
equals
Comparesobj
to this media type to see if they are the same by comparing type, subtype and parameters. Note that the case-sensitivity of parameter values is dependent on the semantics of the parameter name, see HTTP/1.1. This method assumes that values are case-sensitive.Note that the
equals(...)
implementation does not perform a class equality check (this.getClass() == obj.getClass()
). Therefore any class that extends fromMediaType
class and needs to override one of theequals(...)
andhashCode()
methods must always override both methods to ensure the contract betweenObject.equals(java.lang.Object)
andObject.hashCode()
does not break. -
hashCode
public int hashCode()Generate a hash code from the type, subtype and parameters.Note that the
equals(java.lang.Object)
implementation does not perform a class equality check (this.getClass() == obj.getClass()
). Therefore any class that extends fromMediaType
class and needs to override one of theequals(Object)
andhashCode()
methods must always override both methods to ensure the contract betweenObject.equals(java.lang.Object)
andObject.hashCode()
does not break. -
toString
Convert the media type to a string suitable for use as the value of a corresponding HTTP header. -
hasSuffix
Tests if this media type has provided Structured Syntaxsuffix
(RFC 6839).- Parameters:
suffix
- Suffix with or without '+' prefix. If null or empty then returnstrue
if this media type has ANY suffix.- Returns:
true
if media type has specifiedsuffix
or has any suffix if parameter isnull
or empty.
-