Class MediaType
- java.lang.Object
-
- com.google.common.net.MediaType
-
@Beta @GwtCompatible public final class MediaType extends java.lang.Object
Represents an Internet Media Type (also known as a MIME Type or Content Type). This class also supports the concept of media ranges defined by HTTP/1.1. As such, the*character is treated as a wildcard and is used to represent any acceptable type or subtype value. A media type may not have wildcard type with a declared subtype. The*character has no special meaning as part of a parameter. All values for type, subtype, parameter attributes or parameter values must be valid according to RFCs 2045 and 2046.All portions of the media type that are case-insensitive (type, subtype, parameter attributes) are normalized to lowercase. The value of the
charsetparameter is normalized to lowercase, but all others are left as-is.Note that this specifically does not represent the value of the MIME
Content-Typeheader and as such has no support for header-specific considerations such as line folding and comments.For media types that take a charset the predefined constants default to UTF-8 and have a "_UTF_8" suffix. To get a version without a character set, use
withoutParameters().- Since:
- 12.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMediaType.Tokenizer
-
Field Summary
Fields Modifier and Type Field Description static MediaTypeAAC_AUDIOAdvanced Audio Coding.static MediaTypeANY_APPLICATION_TYPEstatic MediaTypeANY_AUDIO_TYPEstatic MediaTypeANY_IMAGE_TYPEstatic MediaTypeANY_TEXT_TYPEstatic MediaTypeANY_TYPEstatic MediaTypeANY_VIDEO_TYPEstatic MediaTypeAPPLE_MOBILE_CONFIGstatic MediaTypeAPPLE_PASSBOOKstatic MediaTypeAPPLICATION_BINARYThis is a non-standard media type, but is commonly used in serving hosted binary files as it is known not to trigger content sniffing in current browsers.private static java.lang.StringAPPLICATION_TYPEstatic MediaTypeAPPLICATION_XML_UTF_8static MediaTypeATOM_UTF_8private static java.lang.StringAUDIO_TYPEstatic MediaTypeBASIC_AUDIOBasic Audio, as defined by RFC 2046.static MediaTypeBMPBitmap file format (bmpfiles).static MediaTypeBZIP2static MediaTypeCACHE_MANIFEST_UTF_8private static java.lang.StringCHARSET_ATTRIBUTEstatic MediaTypeCRWThe Canon Image File Format (crwfiles), a widely-used "raw image" format for cameras.static MediaTypeCSS_UTF_8static MediaTypeCSV_UTF_8static MediaTypeDART_UTF_8Files in the dart programming language.static MediaTypeEOTEmbedded OpenType fonts.static MediaTypeEPUBAs described in the International Digital Publishing Forum EPUB is the distribution and interchange format standard for digital publications and documents.static MediaTypeFLV_VIDEOFlash video.static MediaTypeFORM_DATAstatic MediaTypeGEO_JSONMedia type for the GeoJSON Format, a geospatial data interchange format based on JSON.static MediaTypeGIFstatic MediaTypeGZIPstatic MediaTypeHAL_JSONprivate inthashCodestatic MediaTypeHEIFstatic MediaTypeHTML_UTF_8static MediaTypeI_CALENDAR_UTF_8static MediaTypeICOprivate static java.lang.StringIMAGE_TYPEstatic MediaTypeJAVASCRIPT_UTF_8RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascriptmay be necessary in certain situations for compatibility.static MediaTypeJOSEstatic MediaTypeJOSE_JSONstatic MediaTypeJP2Kstatic MediaTypeJPEGstatic MediaTypeJSON_UTF_8static MediaTypeKEY_ARCHIVEAs described in PKCS #12: Personal Information Exchange Syntax Standard, PKCS #12 defines an archive file format for storing many cryptography objects as a single file.static MediaTypeKMLstatic MediaTypeKMZOGC KML (Keyhole Markup Language), compressed using the ZIP format into KMZ archives.private static java.util.Map<MediaType,MediaType>KNOWN_TYPESstatic MediaTypeL16_AUDIOL16 audio, as defined by RFC 2586.static MediaTypeL24_AUDIOL24 audio, as defined by RFC 3190.private static CharMatcherLINEAR_WHITE_SPACEstatic MediaTypeMANIFEST_JSON_UTF_8static MediaTypeMBOXThe mbox database format.static MediaTypeMICROSOFT_EXCELMicrosoft Excel spreadsheets.static MediaTypeMICROSOFT_OUTLOOKMicrosoft Outlook items.static MediaTypeMICROSOFT_POWERPOINTMicrosoft Powerpoint presentations.static MediaTypeMICROSOFT_WORDMicrosoft Word documents.static MediaTypeMP4_AUDIOstatic MediaTypeMP4_VIDEOstatic MediaTypeMPEG_AUDIOstatic MediaTypeMPEG_VIDEOstatic MediaTypeNACL_APPLICATIONNaCl applications.static MediaTypeNACL_PORTABLE_APPLICATIONNaCl portable applications.static MediaTypeOCTET_STREAMstatic MediaTypeOGG_AUDIOstatic MediaTypeOGG_CONTAINERstatic MediaTypeOGG_VIDEOstatic MediaTypeOOXML_DOCUMENTstatic MediaTypeOOXML_PRESENTATIONstatic MediaTypeOOXML_SHEETstatic MediaTypeOPENDOCUMENT_GRAPHICSstatic MediaTypeOPENDOCUMENT_PRESENTATIONstatic MediaTypeOPENDOCUMENT_SPREADSHEETstatic MediaTypeOPENDOCUMENT_TEXTprivate static Joiner.MapJoinerPARAMETER_JOINERprivate ImmutableListMultimap<java.lang.String,java.lang.String>parametersprivate Optional<java.nio.charset.Charset>parsedCharsetstatic MediaTypePDFstatic MediaTypePLAIN_TEXT_UTF_8static MediaTypePNGstatic MediaTypePOSTSCRIPTstatic MediaTypePROTOBUFstatic MediaTypePSDstatic MediaTypeQUICKTIMEprivate static CharMatcherQUOTED_TEXT_MATCHERstatic MediaTypeRDF_XML_UTF_8RDF/XML documents, which are XML serializations of Resource Description Framework graphs.static MediaTypeRTF_UTF_8static MediaTypeSFNTstatic MediaTypeSHOCKWAVE_FLASHstatic MediaTypeSKETCHUPskpfiles produced by the 3D Modeling software SketchUpstatic MediaTypeSOAP_XML_UTF_8As described in RFC 3902, this constant (application/soap+xml) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.private java.lang.Stringsubtypestatic MediaTypeSVG_UTF_8static MediaTypeTARstatic MediaTypeTEXT_JAVASCRIPT_UTF_8RFC 4329 declaresapplication/javascriptto be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.private static java.lang.StringTEXT_TYPEstatic MediaTypeTHREE_GPP_VIDEOThe 3GP multimedia container format.static MediaTypeTHREE_GPP2_VIDEOThe 3G2 multimedia container format.static MediaTypeTIFFprivate static CharMatcherTOKEN_MATCHERMatcher for type, subtype and attributes.private java.lang.StringtoStringstatic MediaTypeTSV_UTF_8private java.lang.Stringtypeprivate static ImmutableListMultimap<java.lang.String,java.lang.String>UTF_8_CONSTANT_PARAMETERSstatic MediaTypeVCARD_UTF_8private static java.lang.StringVIDEO_TYPEstatic MediaTypeVND_REAL_AUDIOReal Audio.static MediaTypeVND_WAVE_AUDIOWAVE format, as defined by RFC 2361.static MediaTypeVORBIS_AUDIOVorbis Audio, as defined by RFC 5215.static MediaTypeVTT_UTF_8As described in the VTT spec, this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.static MediaTypeWASM_APPLICATIONWASM applications.static MediaTypeWAX_AUDIOWindows Media metafiles.static MediaTypeWEBM_AUDIOstatic MediaTypeWEBM_VIDEOstatic MediaTypeWEBPprivate static java.lang.StringWILDCARDstatic MediaTypeWMA_AUDIOWindows Media Audio.static MediaTypeWML_UTF_8UTF-8 encoded Wireless Markup Language.static MediaTypeWMVstatic MediaTypeWOFFWeb Open Font Format (WOFF) defined by the W3C.static MediaTypeWOFF2Web Open Font Format (WOFF) version 2 defined by the W3C.static MediaTypeXHTML_UTF_8static MediaTypeXML_UTF_8As described in RFC 3023, this constant (text/xml) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8is provided for documents that are intended for applications.static MediaTypeXRD_UTF_8Extensible Resource Descriptors.static MediaTypeZIP
-
Constructor Summary
Constructors Modifier Constructor Description privateMediaType(java.lang.String type, java.lang.String subtype, ImmutableListMultimap<java.lang.String,java.lang.String> parameters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static MediaTypeaddKnownType(MediaType mediaType)Optional<java.nio.charset.Charset>charset()Returns an optional charset for the value of the charset parameter if it is specified.private java.lang.StringcomputeToString()static MediaTypecreate(java.lang.String type, java.lang.String subtype)Creates a new media type with the given type and subtype.private static MediaTypecreate(java.lang.String type, java.lang.String subtype, Multimap<java.lang.String,java.lang.String> parameters)(package private) static MediaTypecreateApplicationType(java.lang.String subtype)Creates a media type with the "application" type and the given subtype.(package private) static MediaTypecreateAudioType(java.lang.String subtype)Creates a media type with the "audio" type and the given subtype.private static MediaTypecreateConstant(java.lang.String type, java.lang.String subtype)private static MediaTypecreateConstantUtf8(java.lang.String type, java.lang.String subtype)(package private) static MediaTypecreateImageType(java.lang.String subtype)Creates a media type with the "image" type and the given subtype.(package private) static MediaTypecreateTextType(java.lang.String subtype)Creates a media type with the "text" type and the given subtype.(package private) static MediaTypecreateVideoType(java.lang.String subtype)Creates a media type with the "video" type and the given subtype.booleanequals(java.lang.Object obj)private static java.lang.StringescapeAndQuote(java.lang.String value)inthashCode()booleanhasWildcard()Returns true if either the type or subtype is the wildcard.booleanis(MediaType mediaTypeRange)Returnstrueif this instance falls within the range (as defined by the HTTP Accept header) given by the argument according to three criteria: The type of the argument is the wildcard or equal to the type of this instance.private static java.lang.StringnormalizeParameterValue(java.lang.String attribute, java.lang.String value)private static java.lang.StringnormalizeToken(java.lang.String token)ImmutableListMultimap<java.lang.String,java.lang.String>parameters()Returns a multimap containing the parameters of this media type.private java.util.Map<java.lang.String,ImmutableMultiset<java.lang.String>>parametersAsMap()static MediaTypeparse(java.lang.String input)Parses a media type from its string representation.java.lang.Stringsubtype()Returns the media subtype.java.lang.StringtoString()Returns the string representation of this media type in the format described in RFC 2045.java.lang.Stringtype()Returns the top-level media type.MediaTypewithCharset(java.nio.charset.Charset charset)Returns a new instance with the same type and subtype as this instance, with thecharsetparameter set to thenameof the given charset.MediaTypewithoutParameters()Returns a new instance with the same type and subtype as this instance, but without any parameters.MediaTypewithParameter(java.lang.String attribute, java.lang.String value)Replaces all parameters with the given attribute with a single parameter with the given value.MediaTypewithParameters(Multimap<java.lang.String,java.lang.String> parameters)Replaces all parameters with the given parameters.MediaTypewithParameters(java.lang.String attribute, java.lang.Iterable<java.lang.String> values)Replaces all parameters with the given attribute with parameters using the given values.
-
-
-
Field Detail
-
CHARSET_ATTRIBUTE
private static final java.lang.String CHARSET_ATTRIBUTE
- See Also:
- Constant Field Values
-
UTF_8_CONSTANT_PARAMETERS
private static final ImmutableListMultimap<java.lang.String,java.lang.String> UTF_8_CONSTANT_PARAMETERS
-
TOKEN_MATCHER
private static final CharMatcher TOKEN_MATCHER
Matcher for type, subtype and attributes.
-
QUOTED_TEXT_MATCHER
private static final CharMatcher QUOTED_TEXT_MATCHER
-
LINEAR_WHITE_SPACE
private static final CharMatcher LINEAR_WHITE_SPACE
-
APPLICATION_TYPE
private static final java.lang.String APPLICATION_TYPE
- See Also:
- Constant Field Values
-
AUDIO_TYPE
private static final java.lang.String AUDIO_TYPE
- See Also:
- Constant Field Values
-
IMAGE_TYPE
private static final java.lang.String IMAGE_TYPE
- See Also:
- Constant Field Values
-
TEXT_TYPE
private static final java.lang.String TEXT_TYPE
- See Also:
- Constant Field Values
-
VIDEO_TYPE
private static final java.lang.String VIDEO_TYPE
- See Also:
- Constant Field Values
-
WILDCARD
private static final java.lang.String WILDCARD
- See Also:
- Constant Field Values
-
ANY_TYPE
public static final MediaType ANY_TYPE
-
ANY_TEXT_TYPE
public static final MediaType ANY_TEXT_TYPE
-
ANY_IMAGE_TYPE
public static final MediaType ANY_IMAGE_TYPE
-
ANY_AUDIO_TYPE
public static final MediaType ANY_AUDIO_TYPE
-
ANY_VIDEO_TYPE
public static final MediaType ANY_VIDEO_TYPE
-
ANY_APPLICATION_TYPE
public static final MediaType ANY_APPLICATION_TYPE
-
CACHE_MANIFEST_UTF_8
public static final MediaType CACHE_MANIFEST_UTF_8
-
CSS_UTF_8
public static final MediaType CSS_UTF_8
-
CSV_UTF_8
public static final MediaType CSV_UTF_8
-
HTML_UTF_8
public static final MediaType HTML_UTF_8
-
I_CALENDAR_UTF_8
public static final MediaType I_CALENDAR_UTF_8
-
PLAIN_TEXT_UTF_8
public static final MediaType PLAIN_TEXT_UTF_8
-
TEXT_JAVASCRIPT_UTF_8
public static final MediaType TEXT_JAVASCRIPT_UTF_8
RFC 4329 declaresapplication/javascriptto be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.
-
TSV_UTF_8
public static final MediaType TSV_UTF_8
- Since:
- 15.0
-
VCARD_UTF_8
public static final MediaType VCARD_UTF_8
-
WML_UTF_8
public static final MediaType WML_UTF_8
UTF-8 encoded Wireless Markup Language.- Since:
- 13.0
-
XML_UTF_8
public static final MediaType XML_UTF_8
As described in RFC 3023, this constant (text/xml) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8is provided for documents that are intended for applications.
-
VTT_UTF_8
public static final MediaType VTT_UTF_8
As described in the VTT spec, this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.- Since:
- 20.0
-
BMP
public static final MediaType BMP
Bitmap file format (bmpfiles).- Since:
- 13.0
-
CRW
public static final MediaType CRW
The Canon Image File Format (crwfiles), a widely-used "raw image" format for cameras. It is found in/etc/mime.types, e.g. in Debian 3.48-1.- Since:
- 15.0
-
GIF
public static final MediaType GIF
-
ICO
public static final MediaType ICO
-
JPEG
public static final MediaType JPEG
-
PNG
public static final MediaType PNG
-
PSD
public static final MediaType PSD
The Photoshop File Format (psdfiles) as defined by IANA, and found in/etc/mime.types, e.g. of the Apache HTTPD project; for the specification, see Adobe Photoshop Document Format and Wikipedia; this is the regular output/input of Photoshop (which can also export to various image formats; note that files with extension "PSB" are in a distinct but related format).This is a more recent replacement for the older, experimental type
x-photoshop: RFC-2046.6.- Since:
- 15.0
-
SVG_UTF_8
public static final MediaType SVG_UTF_8
-
TIFF
public static final MediaType TIFF
-
WEBP
public static final MediaType WEBP
- Since:
- 13.0
-
HEIF
public static final MediaType HEIF
- Since:
- 28.1
-
JP2K
public static final MediaType JP2K
- Since:
- 28.1
-
MP4_AUDIO
public static final MediaType MP4_AUDIO
-
MPEG_AUDIO
public static final MediaType MPEG_AUDIO
-
OGG_AUDIO
public static final MediaType OGG_AUDIO
-
WEBM_AUDIO
public static final MediaType WEBM_AUDIO
-
BASIC_AUDIO
public static final MediaType BASIC_AUDIO
Basic Audio, as defined by RFC 2046.- Since:
- 20.0
-
AAC_AUDIO
public static final MediaType AAC_AUDIO
Advanced Audio Coding. For more information, see Advanced Audio Coding.- Since:
- 20.0
-
VORBIS_AUDIO
public static final MediaType VORBIS_AUDIO
Vorbis Audio, as defined by RFC 5215.- Since:
- 20.0
-
WMA_AUDIO
public static final MediaType WMA_AUDIO
Windows Media Audio. For more information, see file name extensions for Windows Media metafiles.- Since:
- 20.0
-
WAX_AUDIO
public static final MediaType WAX_AUDIO
Windows Media metafiles. For more information, see file name extensions for Windows Media metafiles.- Since:
- 20.0
-
VND_REAL_AUDIO
public static final MediaType VND_REAL_AUDIO
Real Audio. For more information, see this link.- Since:
- 20.0
-
VND_WAVE_AUDIO
public static final MediaType VND_WAVE_AUDIO
WAVE format, as defined by RFC 2361.- Since:
- 20.0
-
MP4_VIDEO
public static final MediaType MP4_VIDEO
-
MPEG_VIDEO
public static final MediaType MPEG_VIDEO
-
OGG_VIDEO
public static final MediaType OGG_VIDEO
-
QUICKTIME
public static final MediaType QUICKTIME
-
WEBM_VIDEO
public static final MediaType WEBM_VIDEO
-
WMV
public static final MediaType WMV
-
FLV_VIDEO
public static final MediaType FLV_VIDEO
Flash video. For more information, see this link.- Since:
- 20.0
-
THREE_GPP_VIDEO
public static final MediaType THREE_GPP_VIDEO
The 3GP multimedia container format. For more information, see 3GPP TS 26.244.- Since:
- 20.0
-
THREE_GPP2_VIDEO
public static final MediaType THREE_GPP2_VIDEO
The 3G2 multimedia container format. For more information, see 3GPP2 C.S0050-B.- Since:
- 20.0
-
APPLICATION_XML_UTF_8
public static final MediaType APPLICATION_XML_UTF_8
As described in RFC 3023, this constant (application/xml) is used for XML documents that are "unreadable by casual users."XML_UTF_8is provided for documents that may be read by users.- Since:
- 14.0
-
ATOM_UTF_8
public static final MediaType ATOM_UTF_8
-
BZIP2
public static final MediaType BZIP2
-
DART_UTF_8
public static final MediaType DART_UTF_8
Files in the dart programming language.- Since:
- 19.0
-
APPLE_PASSBOOK
public static final MediaType APPLE_PASSBOOK
- Since:
- 19.0
-
EOT
public static final MediaType EOT
Embedded OpenType fonts. This is registered with the IANA.- Since:
- 17.0
-
EPUB
public static final MediaType EPUB
As described in the International Digital Publishing Forum EPUB is the distribution and interchange format standard for digital publications and documents. This media type is defined in the EPUB Open Container Format specification.- Since:
- 15.0
-
FORM_DATA
public static final MediaType FORM_DATA
-
KEY_ARCHIVE
public static final MediaType KEY_ARCHIVE
As described in PKCS #12: Personal Information Exchange Syntax Standard, PKCS #12 defines an archive file format for storing many cryptography objects as a single file.- Since:
- 15.0
-
APPLICATION_BINARY
public static final MediaType APPLICATION_BINARY
This is a non-standard media type, but is commonly used in serving hosted binary files as it is known not to trigger content sniffing in current browsers. It should not be used in other situations as it is not specified by any RFC and does not appear in the /IANA MIME Media Types list. ConsiderOCTET_STREAMfor binary data that is not being served to a browser.- Since:
- 14.0
-
GEO_JSON
public static final MediaType GEO_JSON
Media type for the GeoJSON Format, a geospatial data interchange format based on JSON.- Since:
- 28.0
-
GZIP
public static final MediaType GZIP
-
HAL_JSON
public static final MediaType HAL_JSON
- Since:
- 26.0
-
JAVASCRIPT_UTF_8
public static final MediaType JAVASCRIPT_UTF_8
RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascriptmay be necessary in certain situations for compatibility.
-
JOSE
public static final MediaType JOSE
- Since:
- 27.1
-
JOSE_JSON
public static final MediaType JOSE_JSON
- Since:
- 27.1
-
JSON_UTF_8
public static final MediaType JSON_UTF_8
-
MANIFEST_JSON_UTF_8
public static final MediaType MANIFEST_JSON_UTF_8
- Since:
- 19.0
-
KML
public static final MediaType KML
-
KMZ
public static final MediaType KMZ
OGC KML (Keyhole Markup Language), compressed using the ZIP format into KMZ archives.
-
MBOX
public static final MediaType MBOX
The mbox database format.- Since:
- 13.0
-
APPLE_MOBILE_CONFIG
public static final MediaType APPLE_MOBILE_CONFIG
- Since:
- 18.0
-
MICROSOFT_EXCEL
public static final MediaType MICROSOFT_EXCEL
Microsoft Excel spreadsheets.
-
MICROSOFT_OUTLOOK
public static final MediaType MICROSOFT_OUTLOOK
Microsoft Outlook items.- Since:
- 27.1
-
MICROSOFT_POWERPOINT
public static final MediaType MICROSOFT_POWERPOINT
Microsoft Powerpoint presentations.
-
MICROSOFT_WORD
public static final MediaType MICROSOFT_WORD
Microsoft Word documents.
-
WASM_APPLICATION
public static final MediaType WASM_APPLICATION
WASM applications. For more information see the Web Assembly overview.- Since:
- 27.0
-
NACL_APPLICATION
public static final MediaType NACL_APPLICATION
NaCl applications. For more information see the Developer Guide for Native Client Application Structure.- Since:
- 20.0
-
NACL_PORTABLE_APPLICATION
public static final MediaType NACL_PORTABLE_APPLICATION
NaCl portable applications. For more information see the Developer Guide for Native Client Application Structure.- Since:
- 20.0
-
OCTET_STREAM
public static final MediaType OCTET_STREAM
-
OGG_CONTAINER
public static final MediaType OGG_CONTAINER
-
OOXML_DOCUMENT
public static final MediaType OOXML_DOCUMENT
-
OOXML_PRESENTATION
public static final MediaType OOXML_PRESENTATION
-
OOXML_SHEET
public static final MediaType OOXML_SHEET
-
OPENDOCUMENT_GRAPHICS
public static final MediaType OPENDOCUMENT_GRAPHICS
-
OPENDOCUMENT_PRESENTATION
public static final MediaType OPENDOCUMENT_PRESENTATION
-
OPENDOCUMENT_SPREADSHEET
public static final MediaType OPENDOCUMENT_SPREADSHEET
-
OPENDOCUMENT_TEXT
public static final MediaType OPENDOCUMENT_TEXT
-
PDF
public static final MediaType PDF
-
POSTSCRIPT
public static final MediaType POSTSCRIPT
-
PROTOBUF
public static final MediaType PROTOBUF
- Since:
- 15.0
-
RDF_XML_UTF_8
public static final MediaType RDF_XML_UTF_8
RDF/XML documents, which are XML serializations of Resource Description Framework graphs.- Since:
- 14.0
-
RTF_UTF_8
public static final MediaType RTF_UTF_8
-
SFNT
public static final MediaType SFNT
- Since:
- 17.0
-
SHOCKWAVE_FLASH
public static final MediaType SHOCKWAVE_FLASH
-
SKETCHUP
public static final MediaType SKETCHUP
skpfiles produced by the 3D Modeling software SketchUp- Since:
- 13.0
-
SOAP_XML_UTF_8
public static final MediaType SOAP_XML_UTF_8
As described in RFC 3902, this constant (application/soap+xml) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.For SOAP 1.1 messages, see
XML_UTF_8per W3C Note on Simple Object Access Protocol (SOAP) 1.1- Since:
- 20.0
-
TAR
public static final MediaType TAR
-
WOFF
public static final MediaType WOFF
- Since:
- 17.0
-
WOFF2
public static final MediaType WOFF2
Web Open Font Format (WOFF) version 2 defined by the W3C.- Since:
- 20.0
-
XHTML_UTF_8
public static final MediaType XHTML_UTF_8
-
XRD_UTF_8
public static final MediaType XRD_UTF_8
Extensible Resource Descriptors. This is not yet registered with the IANA, but it is specified by OASIS in the XRD definition and implemented in projects such as WebFinger.- Since:
- 14.0
-
ZIP
public static final MediaType ZIP
-
type
private final java.lang.String type
-
subtype
private final java.lang.String subtype
-
parameters
private final ImmutableListMultimap<java.lang.String,java.lang.String> parameters
-
toString
private java.lang.String toString
-
hashCode
private int hashCode
-
parsedCharset
private Optional<java.nio.charset.Charset> parsedCharset
-
PARAMETER_JOINER
private static final Joiner.MapJoiner PARAMETER_JOINER
-
-
Constructor Detail
-
MediaType
private MediaType(java.lang.String type, java.lang.String subtype, ImmutableListMultimap<java.lang.String,java.lang.String> parameters)
-
-
Method Detail
-
createConstant
private static MediaType createConstant(java.lang.String type, java.lang.String subtype)
-
createConstantUtf8
private static MediaType createConstantUtf8(java.lang.String type, java.lang.String subtype)
-
type
public java.lang.String type()
Returns the top-level media type. For example,"text"in"text/plain".
-
subtype
public java.lang.String subtype()
Returns the media subtype. For example,"plain"in"text/plain".
-
parameters
public ImmutableListMultimap<java.lang.String,java.lang.String> parameters()
Returns a multimap containing the parameters of this media type.
-
parametersAsMap
private java.util.Map<java.lang.String,ImmutableMultiset<java.lang.String>> parametersAsMap()
-
charset
public Optional<java.nio.charset.Charset> charset()
Returns an optional charset for the value of the charset parameter if it is specified.- Throws:
java.lang.IllegalStateException- if multiple charset values have been set for this media typejava.nio.charset.IllegalCharsetNameException- if a charset value is present, but illegaljava.nio.charset.UnsupportedCharsetException- if a charset value is present, but no support is available in this instance of the Java virtual machine
-
withoutParameters
public MediaType withoutParameters()
Returns a new instance with the same type and subtype as this instance, but without any parameters.
-
withParameters
public MediaType withParameters(Multimap<java.lang.String,java.lang.String> parameters)
Replaces all parameters with the given parameters.- Throws:
java.lang.IllegalArgumentException- if any parameter or value is invalid
-
withParameters
public MediaType withParameters(java.lang.String attribute, java.lang.Iterable<java.lang.String> values)
Replaces all parameters with the given attribute with parameters using the given values. If there are no values, any existing parameters with the given attribute are removed.- Throws:
java.lang.IllegalArgumentException- if eitherattributeorvaluesis invalid- Since:
- 24.0
-
withParameter
public MediaType withParameter(java.lang.String attribute, java.lang.String value)
Replaces all parameters with the given attribute with a single parameter with the given value. If multiple parameters with the same attributes are necessary usewithParameters(String, Iterable). PreferwithCharset(java.nio.charset.Charset)for setting thecharsetparameter when using aCharsetobject.- Throws:
java.lang.IllegalArgumentException- if eitherattributeorvalueis invalid
-
withCharset
public MediaType withCharset(java.nio.charset.Charset charset)
Returns a new instance with the same type and subtype as this instance, with thecharsetparameter set to thenameof the given charset. Only onecharsetparameter will be present on the new instance regardless of the number set on this one.If a charset must be specified that is not supported on this JVM (and thus is not representable as a
Charsetinstance, usewithParameter(java.lang.String, java.lang.String).
-
hasWildcard
public boolean hasWildcard()
Returns true if either the type or subtype is the wildcard.
-
is
public boolean is(MediaType mediaTypeRange)
Returnstrueif this instance falls within the range (as defined by the HTTP Accept header) given by the argument according to three criteria:- The type of the argument is the wildcard or equal to the type of this instance.
- The subtype of the argument is the wildcard or equal to the subtype of this instance.
- All of the parameters present in the argument are present in this instance.
For example:
PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8) // true PLAIN_TEXT_UTF_8.is(HTML_UTF_8) // false PLAIN_TEXT_UTF_8.is(ANY_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_IMAGE_TYPE) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_8)) // true PLAIN_TEXT_UTF_8.withoutParameters().is(ANY_TEXT_TYPE.withCharset(UTF_8)) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_16)) // falseNote that while it is possible to have the same parameter declared multiple times within a media type this method does not consider the number of occurrences of a parameter. For example,
"text/plain; charset=UTF-8"satisfies"text/plain; charset=UTF-8; charset=UTF-8".
-
create
public static MediaType create(java.lang.String type, java.lang.String subtype)
Creates a new media type with the given type and subtype.- Throws:
java.lang.IllegalArgumentException- if type or subtype is invalid or if a wildcard is used for the type, but not the subtype.
-
create
private static MediaType create(java.lang.String type, java.lang.String subtype, Multimap<java.lang.String,java.lang.String> parameters)
-
createApplicationType
static MediaType createApplicationType(java.lang.String subtype)
Creates a media type with the "application" type and the given subtype.- Throws:
java.lang.IllegalArgumentException- if subtype is invalid
-
createAudioType
static MediaType createAudioType(java.lang.String subtype)
Creates a media type with the "audio" type and the given subtype.- Throws:
java.lang.IllegalArgumentException- if subtype is invalid
-
createImageType
static MediaType createImageType(java.lang.String subtype)
Creates a media type with the "image" type and the given subtype.- Throws:
java.lang.IllegalArgumentException- if subtype is invalid
-
createTextType
static MediaType createTextType(java.lang.String subtype)
Creates a media type with the "text" type and the given subtype.- Throws:
java.lang.IllegalArgumentException- if subtype is invalid
-
createVideoType
static MediaType createVideoType(java.lang.String subtype)
Creates a media type with the "video" type and the given subtype.- Throws:
java.lang.IllegalArgumentException- if subtype is invalid
-
normalizeToken
private static java.lang.String normalizeToken(java.lang.String token)
-
normalizeParameterValue
private static java.lang.String normalizeParameterValue(java.lang.String attribute, java.lang.String value)
-
parse
public static MediaType parse(java.lang.String input)
Parses a media type from its string representation.- Throws:
java.lang.IllegalArgumentException- if the input is not parsable
-
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()
Returns the string representation of this media type in the format described in RFC 2045.- Overrides:
toStringin classjava.lang.Object
-
computeToString
private java.lang.String computeToString()
-
escapeAndQuote
private static java.lang.String escapeAndQuote(java.lang.String value)
-
-