- All Superinterfaces:
Comparable<HttpMediaType>,MediaType,Predicate<HttpMediaType>
public sealed interface HttpMediaType
extends Predicate<HttpMediaType>, Comparable<HttpMediaType>, MediaType
Media type used in HTTP headers, in addition to the media type definition, these may contain additional
parameters, such as
QUALITY_FACTOR_PARAMETER and CHARSET_PARAMETER.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final HttpMediaTypeapplication/jsonmedia type without parameters.static final HttpMediaTypeapplication/octet-streammedia type without parameters.static final StringThe media type "charset" parameter name.static final Predicate<HttpMediaType>Predicate to test ifMediaTypeistext/event-streamwithout any parameter or with parameter "element-type".static final Predicate<HttpMediaType>static final HttpMediaTypeapplication/json media type with UTF-8 charset.static final HttpMediaTypetext/plain media type with UTF-8 charset.static final StringThe media type quality factor "q" parameter name.static final HttpMediaTypetext/plainmedia type without parameters. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpMediaType.Builderbuilder()A fluent API builder for creating customized Media type instances.charset()GetsOptionalvalue of charset parameter.static HttpMediaTypeCreate a new HTTP media type from media type.static HttpMediaTypeParse media type from the provided string.The underlying media type.Read-only parameter map.doubleQuality factor, if not defined, defaults to 1.default Stringsubtype()booleantest(HttpMediaType other) Check if this media type is compatible with another media type.booleanCheck if this media type is compatible with another media type.text()Text of this media type, to be used on the wire.default Stringtype()default HttpMediaTypewithCharset(String charset) Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.default HttpMediaTypewithCharset(Charset charset) Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.default HttpMediaTypewithParameter(String name, String value) Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied custom parameter.Methods inherited from interface java.lang.Comparable
compareToMethods inherited from interface io.helidon.common.media.type.MediaType
fullType, hasSuffix, isWildcardSubtype, isWildcardType
-
Field Details
-
CHARSET_PARAMETER
The media type "charset" parameter name.- See Also:
-
QUALITY_FACTOR_PARAMETER
The media type quality factor "q" parameter name.- See Also:
-
APPLICATION_JSON
application/jsonmedia type without parameters. -
JSON_UTF_8
application/json media type with UTF-8 charset. -
TEXT_PLAIN
text/plainmedia type without parameters. -
PLAINTEXT_UTF_8
text/plain media type with UTF-8 charset. -
APPLICATION_OCTET_STREAM
application/octet-streammedia type without parameters. -
JSON_PREDICATE
-
JSON_EVENT_STREAM_PREDICATE
Predicate to test ifMediaTypeistext/event-streamwithout any parameter or with parameter "element-type". This "element-type" has to be equal to "application/json".
-
-
Method Details
-
builder
A fluent API builder for creating customized Media type instances.- Returns:
- a new builder
-
create
Create a new HTTP media type from media type.- Parameters:
mediaType- media type- Returns:
- a new HTTP media type without any parameters
-
create
Parse media type from the provided string.- Parameters:
mediaTypeString- media type string- Returns:
- HTTP media type parsed from the string
-
mediaType
MediaType mediaType()The underlying media type.- Returns:
- media type
-
qualityFactor
double qualityFactor()Quality factor, if not defined, defaults to 1.- Returns:
- quality factor
-
parameters
Read-only parameter map. Keys are case-insensitive.- Returns:
- an immutable map of parameters.
-
charset
GetsOptionalvalue of charset parameter.- Returns:
- Charset 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.- Specified by:
testin interfacePredicate<HttpMediaType>- Parameters:
other- the media type to compare with.- Returns:
- true if the types are compatible, false otherwise.
-
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.- Parameters:
mediaType- the media type to compare with.- Returns:
- true if the types are compatible, false otherwise.
-
type
-
subtype
-
withCharset
Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter. -
withCharset
Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter. -
text
String text()Text of this media type, to be used on the wire. -
withParameter
Create a newHttpMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied custom parameter.- Parameters:
name- name of the parametervalue- value of the parameter- Returns:
- copy of the current
MediaTypeinstance with the "charset" parameter set to the supplied value.
-