Top Description Inners Fields Constructors Methods
com.google.common.net

public final Class MediaType

extends Object
Class Inheritance
Annotations
@GwtCompatible
@Immutable
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.CharMatcher.ascii, .CharMatcher.javaIsoControl, .Charsets.UTF_8, .Preconditions.checkArgument, .Preconditions.checkNotNull, .Preconditions.checkState

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 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.

Author
Gregory Kick
Since
12.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final MediaType
AAC_AUDIO

Advanced Audio Coding.

public static final MediaType
public static final MediaType
public static final MediaType
ANY_FONT_TYPE

Wildcard matching any "font" top-level media type.

public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
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.

private static final String
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_8 is provided for documents that may be read by users.

public static final MediaType
private static final String
public static final MediaType
BASIC_AUDIO

Basic Audio, as defined by RFC 2046.

public static final MediaType
BMP

Bitmap file format (bmp files).

public static final MediaType
public static final MediaType
private static final String
public static final MediaType
CRW

The Canon Image File Format (crw files), a widely-used "raw image" format for cameras.

public static final MediaType
public static final MediaType
public static final MediaType
DART_UTF_8

Files in the dart programming language.

public static final MediaType
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.

public static final MediaType
FLV_VIDEO

Flash video.

public static final MediaType
FONT_COLLECTION

A collection of font outlines as defined by RFC 8081.

public static final MediaType
public static final MediaType
public static final MediaType
private static final String
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
GEO_JSON

Media type for the GeoJSON Format, a geospatial data interchange format based on JSON.

public static final MediaType
public static final MediaType
public static final MediaType
private int
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
private static final String
public static final MediaType
JAVASCRIPT_UTF_8

RFC 4329 declares this to be the correct media type for JavaScript, but text/javascript may be necessary in certain situations for compatibility.

public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
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.

public static final MediaType
public static final MediaType
KMZ

OGC KML (Keyhole Markup Language), compressed using the ZIP format into KMZ archives.

private static final Map<MediaType, MediaType>
public static final MediaType
L16_AUDIO

L16 audio, as defined by RFC 2586.

public static final MediaType
L24_AUDIO

L24 audio, as defined by RFC 3190.

private static final CharMatcher
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
NACL_APPLICATION

NaCl applications.

public static final MediaType
NACL_PORTABLE_APPLICATION

NaCl portable applications.

public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
OPENSEARCH_DESCRIPTION_UTF_8

OpenSearch Description files are XML files that describe how a website can be used as a search engine by consumers (e.g. web browsers).

private static final Joiner.MapJoiner
private final ImmutableListMultimap<String, String>
private Optional<Charset>
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
public static final MediaType
PSD

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, 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).

public static final MediaType
private static final CharMatcher
public static final MediaType
RDF_XML_UTF_8

RDF/XML documents, which are XML serializations of Resource Description Framework graphs.

public static final MediaType
public static final MediaType
SFNT

RFC 8081 declares font/sfnt to be the correct media type for SFNT, but this may be necessary in certain situations for compatibility.

public static final MediaType
public static final MediaType
SKETCHUP

skp files produced by the 3D Modeling software SketchUp

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.

private final String
public static final MediaType
public static final MediaType
public static final MediaType
TEXT_JAVASCRIPT_UTF_8

RFC 4329 declares application/javascript to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.

private static final String
public static final MediaType
THREE_GPP2_VIDEO

The 3G2 multimedia container format.

public static final MediaType
THREE_GPP_VIDEO

The 3GP multimedia container format.

public static final MediaType
private static final CharMatcher
TOKEN_MATCHER

Matcher for type, subtype and attributes.

private String
public static final MediaType
private final String
private static final ImmutableListMultimap<String, String>
public static final MediaType
private static final String
public static final MediaType
VND_REAL_AUDIO

Real Audio.

public static final MediaType
VND_WAVE_AUDIO

WAVE format, as defined by RFC 2361.

public static final MediaType
VORBIS_AUDIO

Vorbis Audio, as defined by RFC 5215.

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.

public static final MediaType
WASM_APPLICATION

WASM applications.

public static final MediaType
WAX_AUDIO

Windows Media metafiles.

public static final MediaType
public static final MediaType
public static final MediaType
private static final String
public static final MediaType
WMA_AUDIO

Windows Media Audio.

public static final MediaType
public static final MediaType
public static final MediaType
WOFF

RFC 8081 declares font/woff to be the correct media type for WOFF, but this may be necessary in certain situations for compatibility.

public static final MediaType
WOFF2

RFC 8081 declares font/woff2 to be the correct media type for WOFF2, but this may be necessary in certain situations for compatibility.

public static final MediaType
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_8 is provided for documents that are intended for applications.

public static final MediaType
XRD_UTF_8

Extensible Resource Descriptors.

public static final MediaType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static MediaType
public Optional<Charset>
charset()

Returns an optional charset for the value of the charset parameter if it is specified.

private String
private static void
public static MediaType
create(String type, String subtype)

Creates a new media type with the given type and subtype.

private static MediaType
create(String type, String subtype, Multimap<String, String> parameters)

pack-priv static MediaType
createApplicationType(String subtype)

Creates a media type with the "application" type and the given subtype.

pack-priv static MediaType
createAudioType(String subtype)

Creates a media type with the "audio" type and the given subtype.

private static MediaType
createConstant(String type, String subtype)

private static MediaType
pack-priv static MediaType
createFontType(String subtype)

Creates a media type with the "font" type and the given subtype.

pack-priv static MediaType
createImageType(String subtype)

Creates a media type with the "image" type and the given subtype.

pack-priv static MediaType
createTextType(String subtype)

Creates a media type with the "text" type and the given subtype.

pack-priv static MediaType
createVideoType(String subtype)

Creates a media type with the "video" type and the given subtype.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private static String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public boolean
hasWildcard()

Returns true if either the type or subtype is the wildcard.

public boolean
is(MediaType mediaTypeRange)

Returns true if this instance falls within the range (as defined by the HTTP Accept header) given by the argument according to three criteria:

  1. The type of the argument is the wildcard or equal to the type of this instance.
  2. The subtype of the argument is the wildcard or equal to the subtype of this instance.
  3. All of the parameters present in the argument are present in this instance.
private static String
private static String
public ImmutableListMultimap<String, String>
parameters()

Returns a multimap containing the parameters of this media type.

private Map<String, ImmutableMultiset<String>>
public static MediaType
parse(String input)

Parses a media type from its string representation.

public String
subtype()

Returns the media subtype.

public String
toString()

Overrides java.lang.Object.toString.

Returns the string representation of this media type in the format described in RFC 2045.
public String
type()

Returns the top-level media type.

public MediaType
withCharset(Charset charset)

Returns a new instance with the same type and subtype as this instance, with the charset parameter set to the name of the given charset.

public MediaType
withoutParameters()

Returns a new instance with the same type and subtype as this instance, but without any parameters.

public MediaType
withParameter(String attribute, String value)

Replaces all parameters with the given attribute with a single parameter with the given value.

public MediaType
withParameters(Multimap<String, String> parameters)

Replaces all parameters with the given parameters.

public MediaType
withParameters(String attribute, Iterable<String> values)

Replaces all parameters with the given attribute with parameters using the given values.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait