Class MediaType
- java.lang.Object
-
- com.contentgrid.opa.client.rest.http.MediaType
-
public class MediaType extends java.lang.ObjectRepresents a RFC 2046 Media Type. A media type consists oftype/subtypeand MAY be followed by parameters in the form of name=value{code} paris.
-
-
Field Summary
Fields Modifier and Type Field Description static MediaTypeAPPLICATION_JSONstatic MediaTypeAPPLICATION_OCTET_STREAMstatic MediaTypeTEXT_ALLstatic MediaTypeTEXT_PLAINprotected static java.lang.StringWILDCARD
-
Constructor Summary
Constructors Constructor Description MediaType(java.lang.String type, java.lang.String subtype)Create a newMediaTypefor the given primary type and subtype, with empty parameters.MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Create a newMediaTypefor the given type, subtype, and parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<java.nio.charset.Charset>getCharset()Return the character set, as indicated by acharsetparameter, if available.java.lang.StringgetParameter(java.lang.String name)Return a generic parameter value, given a parameter name.java.util.Map<java.lang.String,java.lang.String>getParameters()Returns all media type parameters in a read-only MapdoublegetQualityValue()Return the quality factor, as indicated by aqparameter, if any.java.lang.StringgetSubtype()Return the subtype.java.lang.StringgetType()Return the primary type.booleanincludes(MediaType other)Indicate whether thisMediaTypeincludes the given media type.booleanisWildcardSubtype()Indicates whether the subtype is the wildcard character*or the wildcard character followed by a suffix (e.g.static MediaTypeparseMediaType(java.lang.String mediaType)static java.util.List<MediaType>parseMediaTypes(java.lang.String... mediaTypes)java.lang.StringtoString()static java.lang.StringtoString(java.util.Collection<MediaType> mediaTypes)Return a string representation of the given list ofMediaTypeobjects, to be used in anAcceptorContent-Typeheader.
-
-
-
Field Detail
-
APPLICATION_JSON
public static final MediaType APPLICATION_JSON
-
APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM
-
TEXT_ALL
public static final MediaType TEXT_ALL
-
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
-
WILDCARD
protected static final java.lang.String WILDCARD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype)Create a newMediaTypefor the given primary type and subtype, with empty parameters.- Parameters:
type- the primary typesubtype- the subtype- Throws:
java.lang.IllegalArgumentException- if any of the arguments contain illegal characters
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Create a newMediaTypefor the given type, subtype, and parameters.- Parameters:
type- the primary typesubtype- the subtypeparameters- the parameters, may benull- Throws:
java.lang.IllegalArgumentException- if any of the arguments contain illegal characters
-
-
Method Detail
-
getType
public java.lang.String getType()
Return the primary type.
-
getSubtype
public java.lang.String getSubtype()
Return the subtype.
-
getCharset
public java.util.Optional<java.nio.charset.Charset> getCharset()
Return the character set, as indicated by acharsetparameter, if available.- Returns:
- the character set wrapped in an
Optional, orOptional.empty()if not available
-
isWildcardSubtype
public boolean isWildcardSubtype()
Indicates whether the subtype is the wildcard character*or the wildcard character followed by a suffix (e.g.*+xml).- Returns:
- whether the subtype is a wildcard
-
getParameter
public java.lang.String getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name.- Parameters:
name- the parameter name- Returns:
- the parameter value, or
nullif not present
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Returns all media type parameters in a read-only Map- Returns:
- an immutable map with all parameters, never
null
-
getQualityValue
public double getQualityValue()
Return the quality factor, as indicated by aqparameter, if any. Defaults to1.0.- Returns:
- the quality factor as double value
-
includes
public boolean includes(MediaType other)
Indicate whether thisMediaTypeincludes the given media type. For example,text/*should includestext/plainandtext/html, andapplication/*+xmlincludesapplication/soap+xml.- Parameters:
other- the reference media type with which to compare- Returns:
trueif this media type includes the given media type;falseotherwise
-
parseMediaType
public static MediaType parseMediaType(java.lang.String mediaType)
-
parseMediaTypes
public static java.util.List<MediaType> parseMediaTypes(java.lang.String... mediaTypes)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public static java.lang.String toString(java.util.Collection<MediaType> mediaTypes)
Return a string representation of the given list ofMediaTypeobjects, to be used in anAcceptorContent-Typeheader.- Parameters:
mediaTypes- the media types to create a string representation for- Returns:
- the string representation
-
-