Class MediaType
- java.lang.Object
-
- com.google.common.net.MediaType
-
@Beta @GwtCompatible @Immutable @Deprecated(since="2022-12-01") public final class MediaType extends java.lang.Object
Deprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023Represents 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
charset
parameter is normalized to lowercase, but all others are left as-is.Note that this specifically does not represent the value of the MIME
Content-Type
header 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
-
-
Field Summary
Fields Modifier and Type Field Description static MediaType
ANY_APPLICATION_TYPE
Deprecated.static MediaType
ANY_AUDIO_TYPE
Deprecated.static MediaType
ANY_IMAGE_TYPE
Deprecated.static MediaType
ANY_TEXT_TYPE
Deprecated.static MediaType
ANY_TYPE
Deprecated.static MediaType
ANY_VIDEO_TYPE
Deprecated.static MediaType
APPLICATION_BINARY
Deprecated.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.static MediaType
APPLICATION_XML_UTF_8
Deprecated.static MediaType
ATOM_UTF_8
Deprecated.static MediaType
BMP
Deprecated.static MediaType
BZIP2
Deprecated.static MediaType
CACHE_MANIFEST_UTF_8
Deprecated.static MediaType
CRW
Deprecated.The media type for the Canon Image File Format (crw
files), a widely-used "raw image" format for cameras.static MediaType
CSS_UTF_8
Deprecated.static MediaType
CSV_UTF_8
Deprecated.static MediaType
EPUB
Deprecated.As described in the International Digital Publishing Forum EPUB is the distribution and interchange format standard for digital publications and documents.static MediaType
FORM_DATA
Deprecated.static MediaType
GIF
Deprecated.static MediaType
GZIP
Deprecated.static MediaType
HTML_UTF_8
Deprecated.static MediaType
I_CALENDAR_UTF_8
Deprecated.static MediaType
ICO
Deprecated.static MediaType
JAVASCRIPT_UTF_8
Deprecated.RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility.static MediaType
JPEG
Deprecated.static MediaType
JSON_UTF_8
Deprecated.static MediaType
KEY_ARCHIVE
Deprecated.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.static MediaType
KML
Deprecated.static MediaType
KMZ
Deprecated.static MediaType
MBOX
Deprecated.static MediaType
MICROSOFT_EXCEL
Deprecated.static MediaType
MICROSOFT_POWERPOINT
Deprecated.static MediaType
MICROSOFT_WORD
Deprecated.static MediaType
MP4_AUDIO
Deprecated.static MediaType
MP4_VIDEO
Deprecated.static MediaType
MPEG_AUDIO
Deprecated.static MediaType
MPEG_VIDEO
Deprecated.static MediaType
OCTET_STREAM
Deprecated.static MediaType
OGG_AUDIO
Deprecated.static MediaType
OGG_CONTAINER
Deprecated.static MediaType
OGG_VIDEO
Deprecated.static MediaType
OOXML_DOCUMENT
Deprecated.static MediaType
OOXML_PRESENTATION
Deprecated.static MediaType
OOXML_SHEET
Deprecated.static MediaType
OPENDOCUMENT_GRAPHICS
Deprecated.static MediaType
OPENDOCUMENT_PRESENTATION
Deprecated.static MediaType
OPENDOCUMENT_SPREADSHEET
Deprecated.static MediaType
OPENDOCUMENT_TEXT
Deprecated.static MediaType
PDF
Deprecated.static MediaType
PLAIN_TEXT_UTF_8
Deprecated.static MediaType
PNG
Deprecated.static MediaType
POSTSCRIPT
Deprecated.static MediaType
PROTOBUF
Deprecated.static MediaType
PSD
Deprecated.The media type for the Photoshop File Format (psd
files) as defined by IANA, and found in/etc/mime.types
, e.g.static MediaType
QUICKTIME
Deprecated.static MediaType
RDF_XML_UTF_8
Deprecated.static MediaType
RTF_UTF_8
Deprecated.static MediaType
SHOCKWAVE_FLASH
Deprecated.static MediaType
SKETCHUP
Deprecated.static MediaType
SVG_UTF_8
Deprecated.static MediaType
TAR
Deprecated.static MediaType
TEXT_JAVASCRIPT_UTF_8
Deprecated.RFC 4329 declaresapplication/javascript
to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.static MediaType
TIFF
Deprecated.static MediaType
TSV_UTF_8
Deprecated.static MediaType
VCARD_UTF_8
Deprecated.static MediaType
WEBM_AUDIO
Deprecated.static MediaType
WEBM_VIDEO
Deprecated.static MediaType
WEBP
Deprecated.static MediaType
WML_UTF_8
Deprecated.static MediaType
WMV
Deprecated.static MediaType
XHTML_UTF_8
Deprecated.static MediaType
XML_UTF_8
Deprecated.As described in RFC 3023, this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications.static MediaType
XRD_UTF_8
Deprecated.Media type for Extensible Resource Descriptors.static MediaType
ZIP
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Optional<java.nio.charset.Charset>
charset()
Deprecated.Returns an optional charset for the value of the charset parameter if it is specified.static MediaType
create(java.lang.String type, java.lang.String subtype)
Deprecated.Creates a new media type with the given type and subtype.boolean
equals(java.lang.Object obj)
Deprecated.int
hashCode()
Deprecated.boolean
hasWildcard()
Deprecated.Returns true if either the type or subtype is the wildcard.boolean
is(MediaType mediaTypeRange)
Deprecated.Returnstrue
if 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.ImmutableListMultimap<java.lang.String,java.lang.String>
parameters()
Deprecated.Returns a multimap containing the parameters of this media type.static MediaType
parse(java.lang.String input)
Deprecated.Parses a media type from its string representation.java.lang.String
subtype()
Deprecated.Returns the media subtype.java.lang.String
toString()
Deprecated.Returns the string representation of this media type in the format described in RFC 2045.java.lang.String
type()
Deprecated.Returns the top-level media type.MediaType
withCharset(java.nio.charset.Charset charset)
Deprecated.Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to thename
of the given charset.MediaType
withoutParameters()
Deprecated.Returns a new instance with the same type and subtype as this instance, but without any parameters.MediaType
withParameter(java.lang.String attribute, java.lang.String value)
Deprecated.Replaces all parameters with the given attribute with a single parameter with the given value.MediaType
withParameters(Multimap<java.lang.String,java.lang.String> parameters)
Deprecated.Replaces all parameters with the given parameters.
-
-
-
Field Detail
-
ANY_TYPE
public static final MediaType ANY_TYPE
Deprecated.
-
ANY_TEXT_TYPE
public static final MediaType ANY_TEXT_TYPE
Deprecated.
-
ANY_IMAGE_TYPE
public static final MediaType ANY_IMAGE_TYPE
Deprecated.
-
ANY_AUDIO_TYPE
public static final MediaType ANY_AUDIO_TYPE
Deprecated.
-
ANY_VIDEO_TYPE
public static final MediaType ANY_VIDEO_TYPE
Deprecated.
-
ANY_APPLICATION_TYPE
public static final MediaType ANY_APPLICATION_TYPE
Deprecated.
-
CACHE_MANIFEST_UTF_8
public static final MediaType CACHE_MANIFEST_UTF_8
Deprecated.
-
CSS_UTF_8
public static final MediaType CSS_UTF_8
Deprecated.
-
CSV_UTF_8
public static final MediaType CSV_UTF_8
Deprecated.
-
HTML_UTF_8
public static final MediaType HTML_UTF_8
Deprecated.
-
I_CALENDAR_UTF_8
public static final MediaType I_CALENDAR_UTF_8
Deprecated.
-
PLAIN_TEXT_UTF_8
public static final MediaType PLAIN_TEXT_UTF_8
Deprecated.
-
TEXT_JAVASCRIPT_UTF_8
public static final MediaType TEXT_JAVASCRIPT_UTF_8
Deprecated.RFC 4329 declaresapplication/javascript
to 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
Deprecated.- Since:
- 15.0
-
VCARD_UTF_8
public static final MediaType VCARD_UTF_8
Deprecated.
-
WML_UTF_8
public static final MediaType WML_UTF_8
Deprecated.
-
XML_UTF_8
public static final MediaType XML_UTF_8
Deprecated.As described in RFC 3023, this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications.
-
BMP
public static final MediaType BMP
Deprecated.
-
CRW
public static final MediaType CRW
Deprecated.The media type for the Canon Image File Format (crw
files), a widely-used "raw image" format for cameras. It is found in/etc/mime.types
, e.g. inDebian 3.48-1. - Since:
- 15.0
-
GIF
public static final MediaType GIF
Deprecated.
-
ICO
public static final MediaType ICO
Deprecated.
-
JPEG
public static final MediaType JPEG
Deprecated.
-
PNG
public static final MediaType PNG
Deprecated.
-
PSD
public static final MediaType PSD
Deprecated.The media type for the Photoshop File Format (psd
files) as defined by IANA, and found in/etc/mime.types
, e.g. of the Apache HTTPD project; for the specification, seeAdobe 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
Deprecated.
-
TIFF
public static final MediaType TIFF
Deprecated.
-
WEBP
public static final MediaType WEBP
Deprecated.
-
MP4_AUDIO
public static final MediaType MP4_AUDIO
Deprecated.
-
MPEG_AUDIO
public static final MediaType MPEG_AUDIO
Deprecated.
-
OGG_AUDIO
public static final MediaType OGG_AUDIO
Deprecated.
-
WEBM_AUDIO
public static final MediaType WEBM_AUDIO
Deprecated.
-
MP4_VIDEO
public static final MediaType MP4_VIDEO
Deprecated.
-
MPEG_VIDEO
public static final MediaType MPEG_VIDEO
Deprecated.
-
OGG_VIDEO
public static final MediaType OGG_VIDEO
Deprecated.
-
QUICKTIME
public static final MediaType QUICKTIME
Deprecated.
-
WEBM_VIDEO
public static final MediaType WEBM_VIDEO
Deprecated.
-
WMV
public static final MediaType WMV
Deprecated.
-
APPLICATION_XML_UTF_8
public static final MediaType APPLICATION_XML_UTF_8
Deprecated.
-
ATOM_UTF_8
public static final MediaType ATOM_UTF_8
Deprecated.
-
BZIP2
public static final MediaType BZIP2
Deprecated.
-
EPUB
public static final MediaType EPUB
Deprecated.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
Deprecated.
-
KEY_ARCHIVE
public static final MediaType KEY_ARCHIVE
Deprecated.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
Deprecated.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_STREAM
for binary data that is not being served to a browser.- Since:
- 14.0
-
GZIP
public static final MediaType GZIP
Deprecated.
-
JAVASCRIPT_UTF_8
public static final MediaType JAVASCRIPT_UTF_8
Deprecated.RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility.
-
JSON_UTF_8
public static final MediaType JSON_UTF_8
Deprecated.
-
KML
public static final MediaType KML
Deprecated.
-
KMZ
public static final MediaType KMZ
Deprecated.
-
MBOX
public static final MediaType MBOX
Deprecated.
-
MICROSOFT_EXCEL
public static final MediaType MICROSOFT_EXCEL
Deprecated.
-
MICROSOFT_POWERPOINT
public static final MediaType MICROSOFT_POWERPOINT
Deprecated.
-
MICROSOFT_WORD
public static final MediaType MICROSOFT_WORD
Deprecated.
-
OCTET_STREAM
public static final MediaType OCTET_STREAM
Deprecated.
-
OGG_CONTAINER
public static final MediaType OGG_CONTAINER
Deprecated.
-
OOXML_DOCUMENT
public static final MediaType OOXML_DOCUMENT
Deprecated.
-
OOXML_PRESENTATION
public static final MediaType OOXML_PRESENTATION
Deprecated.
-
OOXML_SHEET
public static final MediaType OOXML_SHEET
Deprecated.
-
OPENDOCUMENT_GRAPHICS
public static final MediaType OPENDOCUMENT_GRAPHICS
Deprecated.
-
OPENDOCUMENT_PRESENTATION
public static final MediaType OPENDOCUMENT_PRESENTATION
Deprecated.
-
OPENDOCUMENT_SPREADSHEET
public static final MediaType OPENDOCUMENT_SPREADSHEET
Deprecated.
-
OPENDOCUMENT_TEXT
public static final MediaType OPENDOCUMENT_TEXT
Deprecated.
-
PDF
public static final MediaType PDF
Deprecated.
-
POSTSCRIPT
public static final MediaType POSTSCRIPT
Deprecated.
-
PROTOBUF
public static final MediaType PROTOBUF
Deprecated.- Since:
- 15.0
-
RDF_XML_UTF_8
public static final MediaType RDF_XML_UTF_8
Deprecated.
-
RTF_UTF_8
public static final MediaType RTF_UTF_8
Deprecated.
-
SHOCKWAVE_FLASH
public static final MediaType SHOCKWAVE_FLASH
Deprecated.
-
SKETCHUP
public static final MediaType SKETCHUP
Deprecated.
-
TAR
public static final MediaType TAR
Deprecated.
-
XHTML_UTF_8
public static final MediaType XHTML_UTF_8
Deprecated.
-
XRD_UTF_8
public static final MediaType XRD_UTF_8
Deprecated.Media type for 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.
-
ZIP
public static final MediaType ZIP
Deprecated.
-
-
Method Detail
-
type
public java.lang.String type()
Deprecated.Returns the top-level media type. For example,"text"
in"text/plain"
.
-
subtype
public java.lang.String subtype()
Deprecated.Returns the media subtype. For example,"plain"
in"text/plain"
.
-
parameters
public ImmutableListMultimap<java.lang.String,java.lang.String> parameters()
Deprecated.Returns a multimap containing the parameters of this media type.
-
charset
public Optional<java.nio.charset.Charset> charset()
Deprecated.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()
Deprecated.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)
Deprecated.Replaces all parameters with the given parameters.- Throws:
java.lang.IllegalArgumentException
- if any parameter or value is invalid
-
withParameter
public MediaType withParameter(java.lang.String attribute, java.lang.String value)
Deprecated.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(com.google.common.collect.Multimap<java.lang.String, java.lang.String>)
. PreferwithCharset(java.nio.charset.Charset)
for setting thecharset
parameter when using aCharset
object.- Throws:
java.lang.IllegalArgumentException
- if eitherattribute
orvalue
is invalid
-
withCharset
public MediaType withCharset(java.nio.charset.Charset charset)
Deprecated.Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to thename
of the given charset. Only onecharset
parameter 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
Charset
instance, usewithParameter(java.lang.String, java.lang.String)
.
-
hasWildcard
public boolean hasWildcard()
Deprecated.Returns true if either the type or subtype is the wildcard.
-
is
public boolean is(MediaType mediaTypeRange)
Deprecated.Returnstrue
if 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)) // false
Note 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)
Deprecated.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.
-
parse
public static MediaType parse(java.lang.String input)
Deprecated.Parses a media type from its string representation.- Throws:
java.lang.IllegalArgumentException
- if the input is not parsable
-
equals
public boolean equals(@Nullable java.lang.Object obj)
Deprecated.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Deprecated.- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Deprecated.Returns the string representation of this media type in the format described in RFC 2045.- Overrides:
toString
in classjava.lang.Object
-
-