MCPcopy Create free account
hub / github.com/antlr/codebuff / MediaType

Class MediaType

output/java_guava/1.4.16/MediaType.java:77–1084  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

75
76
77@Beta
78@GwtCompatible
79@Immutable
80public final class MediaType {
81 private static final String CHARSET_ATTRIBUTE = "charset";
82 private static final ImmutableListMultimap<String, String> UTF_8_CONSTANT_PARAMETERS = ImmutableListMultimap.of(CHARSET_ATTRIBUTE, Ascii.toLowerCase(UTF_8.name()));
83
84 /** Matcher for type, subtype and attributes. */
85 private static final CharMatcher TOKEN_MATCHER = ascii().and(javaIsoControl().negate()).and(CharMatcher.isNot(' ')).and(CharMatcher.noneOf("()<>@,;:\\\"/[]?="));
86 private static final CharMatcher QUOTED_TEXT_MATCHER = ascii().and(CharMatcher.noneOf("\"\\\r"));
87 /*
88 * This matches the same characters as linear-white-space from RFC 822, but we make no effort to
89 * enforce any particular rules with regards to line folding as stated in the class docs.
90 */
91 private static final CharMatcher LINEAR_WHITE_SPACE = CharMatcher.anyOf(" \t\r\n");
92
93 // TODO(gak): make these public?
94 private static final String APPLICATION_TYPE = "application";
95 private static final String AUDIO_TYPE = "audio";
96 private static final String IMAGE_TYPE = "image";
97 private static final String TEXT_TYPE = "text";
98 private static final String VIDEO_TYPE = "video";
99 private static final String WILDCARD = "*";
100 private static final Map<MediaType, MediaType> KNOWN_TYPES = Maps.newHashMap();
101 private static MediaType createConstant(String type, String subtype) {
102 return addKnownType(new MediaType(type, subtype, ImmutableListMultimap.<String, String>of()));
103 }
104
105 private static MediaType createConstantUtf8(String type, String subtype) {
106 return addKnownType(new MediaType(type, subtype, UTF_8_CONSTANT_PARAMETERS));
107 }
108
109 private static MediaType addKnownType(MediaType mediaType) {
110 KNOWN_TYPES.put(mediaType, mediaType);
111 return mediaType;
112 }
113
114 /*
115 * The following constants are grouped by their type and ordered alphabetically by the constant
116 * name within that type. The constant name should be a sensible identifier that is closest to the
117 * "common name" of the media. This is often, but not necessarily the same as the subtype.
118 *
119 * Be sure to declare all constants with the type and subtype in all lowercase. For types that
120 * take a charset (e.g. all text/* types), default to UTF-8 and suffix the constant name with
121 * "_UTF_8".
122 */
123
124
125 public static final MediaType ANY_TYPE = createConstant(WILDCARD, WILDCARD);
126
127
128 public static final MediaType ANY_TEXT_TYPE = createConstant(TEXT_TYPE, WILDCARD);
129
130
131 public static final MediaType ANY_IMAGE_TYPE = createConstant(IMAGE_TYPE, WILDCARD);
132
133
134 public static final MediaType ANY_AUDIO_TYPE = createConstant(AUDIO_TYPE, WILDCARD);

Callers

nothing calls this directly

Calls 14

ofMethod · 0.95
toLowerCaseMethod · 0.95
isNotMethod · 0.95
noneOfMethod · 0.95
anyOfMethod · 0.95
newHashMapMethod · 0.95
createConstantMethod · 0.95
createConstantUtf8Method · 0.95
onMethod · 0.95
andMethod · 0.45
asciiMethod · 0.45
negateMethod · 0.45

Tested by

no test coverage detected