Class MediaType
- java.lang.Object
-
- io.helidon.common.http.MediaType
-
- All Implemented Interfaces:
AcceptPredicate<MediaType>,Predicate<MediaType>
public final class MediaType extends Object implements AcceptPredicate<MediaType>
An abstraction for a media type. Instances are immutable.- See Also:
- HTTP/1.1 section 3.7
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMediaType.BuilderA fluent API builder to create instances ofMediaType.
-
Field Summary
Fields Modifier and Type Field Description static MediaTypeAPPLICATION_ATOM_XMLAMediaTypeconstant representingapplication/atom+xmlmedia type.static MediaTypeAPPLICATION_FORM_URLENCODEDAMediaTypeconstant representingapplication/x-www-form-urlencodedmedia type.static MediaTypeAPPLICATION_JSONAMediaTypeconstant representingapplication/jsonmedia type.static MediaTypeAPPLICATION_OCTET_STREAMAMediaTypeconstant representingapplication/octet-streammedia type.static MediaTypeAPPLICATION_OPENAPI_JSONAMediaTypeconstant representing OpenAPI json.static MediaTypeAPPLICATION_OPENAPI_YAMLAMediaTypeconstant representing OpenAPI yaml.static MediaTypeAPPLICATION_SVG_XMLAMediaTypeconstant representingapplication/svg+xmlmedia type.static MediaTypeAPPLICATION_X_YAMLAMediaTypeconstant representing "x" YAML as application.static MediaTypeAPPLICATION_XHTML_XMLAMediaTypeconstant representingapplication/xhtml+xmlmedia type.static MediaTypeAPPLICATION_XMLAMediaTypeconstant representingapplication/xmlmedia type.static MediaTypeAPPLICATION_YAMLAMediaTypeconstant representing pseudo-registered YAML.static StringCHARSET_PARAMETERThe media type "charset" parameter name.static Predicate<MediaType>JSON_PREDICATEstatic MediaTypeMULTIPART_FORM_DATAAMediaTypeconstant representingmultipart/form-datamedia type.static MediaTypeTEXT_HTMLAMediaTypeconstant representingtext/htmlmedia type.static MediaTypeTEXT_PLAINAMediaTypeconstant representingtext/plainmedia type.static MediaTypeTEXT_X_YAMLAMediaTypeconstant representing "x" YAML as text.static MediaTypeTEXT_XMLAMediaTypeconstant representingtext/xmlmedia type.static MediaTypeTEXT_YAMLAMediaTypeconstant representing pseudo-registered YAML as text.static MediaTypeWILDCARDAMediaTypeconstant representing wildcard media type.static Predicate<MediaType>XML_PREDICATE-
Fields inherited from interface io.helidon.common.http.AcceptPredicate
QUALITY_FACTOR_PARAMETER, WILDCARD_VALUE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MediaType.Builderbuilder()A fluent API builder for creating customized Media type instances.Optional<String>charset()GetsOptionalvalue of charset parameter.static MediaTypecreate(String type, String subtype)Creates a new instance ofMediaTypewith the supplied type and subtype.booleanequals(Object obj)Comparesobjto this media type to see if they are the same by comparing type, subtype and parameters.inthashCode()Generate a hash code from the type, subtype and parameters.booleanhasSuffix(String suffix)Tests if this media type has provided Structured Syntaxsuffix(RFC 6839).booleanisWildcardSubtype()Checks if the subtype is a wildcard.booleanisWildcardType()Checks if the primary type is a wildcard.Map<String,String>parameters()Getter for a read-only parameter map.static MediaTypeparse(String input)Parses a media type from its string representation.doublequalityFactor()Gets quality factor parameter ("q") as a double value.Stringsubtype()Getter for subtype.booleantest(MediaType other)Check if this media type is compatible with another media type.StringtoString()Convert the media type to a string suitable for use as the value of a corresponding HTTP header.Stringtype()Getter for primary type.MediaTypewithCharset(String charset)Create a newMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
-
-
-
Field Detail
-
CHARSET_PARAMETER
public static final String CHARSET_PARAMETER
The media type "charset" parameter name.- See Also:
- Constant Field Values
-
WILDCARD
public static final MediaType WILDCARD
AMediaTypeconstant representing wildcard media type.
-
APPLICATION_XML
public static final MediaType APPLICATION_XML
AMediaTypeconstant representingapplication/xmlmedia type.
-
APPLICATION_ATOM_XML
public static final MediaType APPLICATION_ATOM_XML
AMediaTypeconstant representingapplication/atom+xmlmedia type.
-
APPLICATION_XHTML_XML
public static final MediaType APPLICATION_XHTML_XML
AMediaTypeconstant representingapplication/xhtml+xmlmedia type.
-
APPLICATION_SVG_XML
public static final MediaType APPLICATION_SVG_XML
AMediaTypeconstant representingapplication/svg+xmlmedia type.
-
APPLICATION_JSON
public static final MediaType APPLICATION_JSON
AMediaTypeconstant representingapplication/jsonmedia type.
-
APPLICATION_FORM_URLENCODED
public static final MediaType APPLICATION_FORM_URLENCODED
AMediaTypeconstant representingapplication/x-www-form-urlencodedmedia type.
-
MULTIPART_FORM_DATA
public static final MediaType MULTIPART_FORM_DATA
AMediaTypeconstant representingmultipart/form-datamedia type.
-
APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM
AMediaTypeconstant representingapplication/octet-streammedia type.
-
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
AMediaTypeconstant representingtext/plainmedia type.
-
TEXT_XML
public static final MediaType TEXT_XML
AMediaTypeconstant representingtext/xmlmedia type.
-
TEXT_HTML
public static final MediaType TEXT_HTML
AMediaTypeconstant representingtext/htmlmedia type.
-
APPLICATION_OPENAPI_YAML
public static final MediaType APPLICATION_OPENAPI_YAML
AMediaTypeconstant representing OpenAPI yaml.See https://github.com/opengeospatial/WFS_FES/issues/117#issuecomment-402188280
-
APPLICATION_OPENAPI_JSON
public static final MediaType APPLICATION_OPENAPI_JSON
AMediaTypeconstant representing OpenAPI json.
-
APPLICATION_X_YAML
public static final MediaType APPLICATION_X_YAML
AMediaTypeconstant representing "x" YAML as application.
-
APPLICATION_YAML
public static final MediaType APPLICATION_YAML
AMediaTypeconstant representing pseudo-registered YAML. (It is not actually registered.)
-
TEXT_X_YAML
public static final MediaType TEXT_X_YAML
AMediaTypeconstant representing "x" YAML as text.
-
TEXT_YAML
public static final MediaType TEXT_YAML
AMediaTypeconstant representing pseudo-registered YAML as text.
-
-
Method Detail
-
create
public static MediaType create(String type, String subtype)
Creates a new instance ofMediaTypewith the supplied type and subtype.- Parameters:
type- the primary type,nullis equivalent toAcceptPredicate.WILDCARD_VALUEsubtype- the subtype,nullis equivalent toAcceptPredicate.WILDCARD_VALUE- Returns:
- a new media type for the specified type and subtype
-
parse
public static MediaType parse(String input)
Parses a media type from its string representation.- Parameters:
input- the input string representing a media type- Returns:
- parsed
MediaTypeinstance - Throws:
IllegalArgumentException- if the input is not parsableNullPointerException- if the input isnull
-
builder
public static MediaType.Builder builder()
A fluent API builder for creating customized Media type instances.- Returns:
- a new builder
-
type
public String 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
public String 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
public Map<String,String> parameters()
Getter for a read-only parameter map. Keys are case-insensitive.- Returns:
- an immutable map of parameters.
-
withCharset
public MediaType withCharset(String charset)
Create a newMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
-
charset
public Optional<String> charset()
GetsOptionalvalue of charset parameter.- Returns:
- Charset parameter.
-
qualityFactor
public double qualityFactor()
Description copied from interface:AcceptPredicateGets quality factor parameter ("q") as a double value. If missing, then returns1.0- Specified by:
qualityFactorin interfaceAcceptPredicate<MediaType>- Returns:
- Quality factor parameter.
-
test
public boolean test(MediaType other)
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
public boolean equals(Object obj)
Comparesobjto 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 fromMediaTypeclass 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 fromMediaTypeclass 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
public String toString()
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
-
hasSuffix
public boolean hasSuffix(String suffix)
Tests if this media type has provided Structured Syntaxsuffix(RFC 6839).- Parameters:
suffix- Suffix with or without '+' prefix. If null or empty then returnstrueif this media type has ANY suffix.- Returns:
trueif media type has specifiedsuffixor has any suffix if parameter isnullor empty.
-
-