Package io.joshworks.restclient.http
Class MediaType
- java.lang.Object
-
- io.joshworks.restclient.http.MediaType
-
public class MediaType extends java.lang.ObjectAn abstraction for a media type. Instances are immutable.- See Also:
- HTTP/1.1 section 3.7
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAPPLICATION_ATOM_XML"application/atom+xml"static MediaTypeAPPLICATION_ATOM_XML_TYPE"application/atom+xml"static java.lang.StringAPPLICATION_FORM_URLENCODED"application/x-www-form-urlencoded"static MediaTypeAPPLICATION_FORM_URLENCODED_TYPE"application/x-www-form-urlencoded"static java.lang.StringAPPLICATION_JSON"application/json"static MediaTypeAPPLICATION_JSON_TYPE"application/json"static java.lang.StringAPPLICATION_OCTET_STREAM"application/octet-stream"static MediaTypeAPPLICATION_OCTET_STREAM_TYPE"application/octet-stream"static java.lang.StringAPPLICATION_SVG_XML"application/svg+xml"static MediaTypeAPPLICATION_SVG_XML_TYPE"application/svg+xml"static java.lang.StringAPPLICATION_XHTML_XML"application/xhtml+xml"static MediaTypeAPPLICATION_XHTML_XML_TYPE"application/xhtml+xml"static java.lang.StringAPPLICATION_XML"application/xml"static MediaTypeAPPLICATION_XML_TYPE"application/xml"static java.lang.StringMEDIA_TYPE_WILDCARDThe value of a type or subtype wildcard: "*"static java.lang.StringMULTIPART_FORM_DATA"multipart/form-data"static MediaTypeMULTIPART_FORM_DATA_TYPE"multipart/form-data"static java.lang.StringTEXT_HTML"text/html"static MediaTypeTEXT_HTML_TYPE"text/html"static java.lang.StringTEXT_PLAIN"text/plain"static MediaTypeTEXT_PLAIN_TYPE"text/plain"static java.lang.StringTEXT_XML"text/xml"static MediaTypeTEXT_XML_TYPE"text/xml"static java.lang.StringWILDCARD"*/*"static MediaTypeWILDCARD_TYPE"*/*"
-
Constructor Summary
Constructors Constructor Description MediaType()Creates a new instance of MediaType, both type and subtype are wildcards.MediaType(java.lang.String type, java.lang.String subtype)Creates a new instance of MediaType with the supplied type and subtype.MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Creates a new instance of MediaType with the supplied type, subtype and pathParameter.
-
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object obj)static MediaTypegetMimeForFile(java.lang.String fileExtension)java.util.Map<java.lang.String,java.lang.String>getParameters()Getter for a read-only pathParameter map.java.lang.StringgetSubtype()Getter for subtype.java.lang.StringgetType()Getter for primary type.inthashCode()booleanisCompatible(MediaType other)Check if this media type is compatible with another media type.booleanisWildcardSubtype()Checks if the subtype is a wildcardbooleanisWildcardType()Checks if the primary type is a wildcard.java.lang.StringtoString()static MediaTypevalueOf(java.lang.String type)Creates a new instance of MediaType by parsing the supplied string.
-
-
-
Field Detail
-
MEDIA_TYPE_WILDCARD
public static final java.lang.String MEDIA_TYPE_WILDCARD
The value of a type or subtype wildcard: "*"- See Also:
- Constant Field Values
-
WILDCARD
public static final java.lang.String WILDCARD
"*/*"- See Also:
- Constant Field Values
-
WILDCARD_TYPE
public static final MediaType WILDCARD_TYPE
"*/*"
-
APPLICATION_XML
public static final java.lang.String APPLICATION_XML
"application/xml"- See Also:
- Constant Field Values
-
APPLICATION_XML_TYPE
public static final MediaType APPLICATION_XML_TYPE
"application/xml"
-
APPLICATION_ATOM_XML
public static final java.lang.String APPLICATION_ATOM_XML
"application/atom+xml"- See Also:
- Constant Field Values
-
APPLICATION_ATOM_XML_TYPE
public static final MediaType APPLICATION_ATOM_XML_TYPE
"application/atom+xml"
-
APPLICATION_XHTML_XML
public static final java.lang.String APPLICATION_XHTML_XML
"application/xhtml+xml"- See Also:
- Constant Field Values
-
APPLICATION_XHTML_XML_TYPE
public static final MediaType APPLICATION_XHTML_XML_TYPE
"application/xhtml+xml"
-
APPLICATION_SVG_XML
public static final java.lang.String APPLICATION_SVG_XML
"application/svg+xml"- See Also:
- Constant Field Values
-
APPLICATION_SVG_XML_TYPE
public static final MediaType APPLICATION_SVG_XML_TYPE
"application/svg+xml"
-
APPLICATION_JSON
public static final java.lang.String APPLICATION_JSON
"application/json"- See Also:
- Constant Field Values
-
APPLICATION_JSON_TYPE
public static final MediaType APPLICATION_JSON_TYPE
"application/json"
-
APPLICATION_FORM_URLENCODED
public static final java.lang.String APPLICATION_FORM_URLENCODED
"application/x-www-form-urlencoded"- See Also:
- Constant Field Values
-
APPLICATION_FORM_URLENCODED_TYPE
public static final MediaType APPLICATION_FORM_URLENCODED_TYPE
"application/x-www-form-urlencoded"
-
MULTIPART_FORM_DATA
public static final java.lang.String MULTIPART_FORM_DATA
"multipart/form-data"- See Also:
- Constant Field Values
-
MULTIPART_FORM_DATA_TYPE
public static final MediaType MULTIPART_FORM_DATA_TYPE
"multipart/form-data"
-
APPLICATION_OCTET_STREAM
public static final java.lang.String APPLICATION_OCTET_STREAM
"application/octet-stream"- See Also:
- Constant Field Values
-
APPLICATION_OCTET_STREAM_TYPE
public static final MediaType APPLICATION_OCTET_STREAM_TYPE
"application/octet-stream"
-
TEXT_PLAIN
public static final java.lang.String TEXT_PLAIN
"text/plain"- See Also:
- Constant Field Values
-
TEXT_PLAIN_TYPE
public static final MediaType TEXT_PLAIN_TYPE
"text/plain"
-
TEXT_XML
public static final java.lang.String TEXT_XML
"text/xml"- See Also:
- Constant Field Values
-
TEXT_XML_TYPE
public static final MediaType TEXT_XML_TYPE
"text/xml"
-
TEXT_HTML
public static final java.lang.String TEXT_HTML
"text/html"- See Also:
- Constant Field Values
-
TEXT_HTML_TYPE
public static final MediaType TEXT_HTML_TYPE
"text/html"
-
-
Constructor Detail
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)Creates a new instance of MediaType with the supplied type, subtype and pathParameter.- Parameters:
type- the primary type, null is equivalent toMEDIA_TYPE_WILDCARD.subtype- the subtype, null is equivalent toMEDIA_TYPE_WILDCARD.parameters- a map of media type pathParameter, null is the same as an empty map.
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype)Creates a new instance of MediaType with the supplied type and subtype.- Parameters:
type- the primary type, null is equivalent toMEDIA_TYPE_WILDCARDsubtype- the subtype, null is equivalent toMEDIA_TYPE_WILDCARD
-
MediaType
public MediaType()
Creates a new instance of MediaType, both type and subtype are wildcards. Consider using the constantWILDCARD_TYPEinstead.
-
-
Method Detail
-
valueOf
public static MediaType valueOf(java.lang.String type) throws java.lang.IllegalArgumentException
Creates a new instance of MediaType by parsing the supplied string.- Parameters:
type- the media type string- Returns:
- the newly created MediaType
- Throws:
java.lang.IllegalArgumentException- if the supplied string cannot be parsed or is null
-
getMimeForFile
public static MediaType getMimeForFile(java.lang.String fileExtension)
-
getType
public java.lang.String getType()
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
-
getSubtype
public java.lang.String getSubtype()
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
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Getter for a read-only pathParameter map. Keys are case-insensitive.- Returns:
- an immutable map of pathParameter.
-
isCompatible
public boolean isCompatible(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 pathParameter are ignored. The function is commutative.- Parameters:
other- the media type to compare with- Returns:
- true if the types are compatible, false otherwise.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-