MediaType { public static MediaType fromString(String text) { Matcher matcher = MEDIA_TYPE_PATTERN.matcher(text); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid media type string: " + text); } String type; String subType; if (matcher.group(GROUP_INDEX) != null) { type = matcher.group(GROUP_INDEX); subType = matcher.group(GROUP_INDEX); } else { type = matcher.group(TYPE_INDEX); subType = matcher.group(SUBTYPE_INDEX); } Map<String, String> parametersBuilder = new HashMap<>(); Matcher parametersMatcher = PARAMETER_PATTERN.matcher(matcher.group(GROUP_MATCHER_INDEX)); while (parametersMatcher.find()) { parametersBuilder.put(parametersMatcher.group(1), parametersMatcher.group(2)); } return new MediaType(type, subType, Collections.unmodifiableMap(parametersBuilder)); } MediaType(String type, String subType, Map<String, String> parameters);  MediaType(String type, String subType); static MediaType fromString(String text); String getType(); String getSubType(); Map<String, String> getParameters(); String getParameter(String name); boolean matches(MediaType that); boolean isWildCardMediaType(); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); static final MediaType XML; static final MediaType ATOM_XML; static final MediaType MULTIPART; static final MediaType HTTP; static final MediaType ATOM_SVC_XML; static final MediaType JSON; static final MediaType TEXT; static final MediaType WILDCARD_ANY; static final int HASH; static final int GROUP_INDEX; static final int TYPE_INDEX; static final int SUBTYPE_INDEX; static final int GROUP_MATCHER_INDEX; }
@Test(expected = IllegalArgumentException.class) public void testFromStringInvalid() { MediaType.fromString("text;q=0.8"); }