@Test void parseIdentity() { assertThat(MediaType.parse("application/json"), sameInstance(MediaType.APPLICATION_JSON)); }
public static MediaType parse(String input) { Objects.requireNonNull(input, "Parameter 'input' is null!"); Tokenizer tokenizer = new Tokenizer(input); try { String type = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('/'); String subtype = tokenizer.consumeToken(TOKEN_MATCHER); Map<String, String> parameters = new HashMap<>(); while (tokenizer.hasMore()) { tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); tokenizer.consumeCharacter(';'); tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); String attribute = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('='); final String value; if ('"' == tokenizer.previewChar()) { tokenizer.consumeCharacter('"'); StringBuilder valueBuilder = new StringBuilder(); while ('"' != tokenizer.previewChar()) { if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER)); } } value = valueBuilder.toString(); tokenizer.consumeCharacter('"'); } else { value = tokenizer.consumeToken(TOKEN_MATCHER); } parameters.put(attribute, value); } return create(type, subtype, parameters); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + "'", e); } }
MediaType implements AcceptPredicate<MediaType> { public static MediaType parse(String input) { Objects.requireNonNull(input, "Parameter 'input' is null!"); Tokenizer tokenizer = new Tokenizer(input); try { String type = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('/'); String subtype = tokenizer.consumeToken(TOKEN_MATCHER); Map<String, String> parameters = new HashMap<>(); while (tokenizer.hasMore()) { tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); tokenizer.consumeCharacter(';'); tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); String attribute = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('='); final String value; if ('"' == tokenizer.previewChar()) { tokenizer.consumeCharacter('"'); StringBuilder valueBuilder = new StringBuilder(); while ('"' != tokenizer.previewChar()) { if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER)); } } value = valueBuilder.toString(); tokenizer.consumeCharacter('"'); } else { value = tokenizer.consumeToken(TOKEN_MATCHER); } parameters.put(attribute, value); } return create(type, subtype, parameters); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + "'", e); } } }
MediaType implements AcceptPredicate<MediaType> { public static MediaType parse(String input) { Objects.requireNonNull(input, "Parameter 'input' is null!"); Tokenizer tokenizer = new Tokenizer(input); try { String type = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('/'); String subtype = tokenizer.consumeToken(TOKEN_MATCHER); Map<String, String> parameters = new HashMap<>(); while (tokenizer.hasMore()) { tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); tokenizer.consumeCharacter(';'); tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); String attribute = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('='); final String value; if ('"' == tokenizer.previewChar()) { tokenizer.consumeCharacter('"'); StringBuilder valueBuilder = new StringBuilder(); while ('"' != tokenizer.previewChar()) { if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER)); } } value = valueBuilder.toString(); tokenizer.consumeCharacter('"'); } else { value = tokenizer.consumeToken(TOKEN_MATCHER); } parameters.put(attribute, value); } return create(type, subtype, parameters); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + "'", e); } } private  MediaType(String type, String subtype); private  MediaType(Builder builder); }
MediaType implements AcceptPredicate<MediaType> { public static MediaType parse(String input) { Objects.requireNonNull(input, "Parameter 'input' is null!"); Tokenizer tokenizer = new Tokenizer(input); try { String type = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('/'); String subtype = tokenizer.consumeToken(TOKEN_MATCHER); Map<String, String> parameters = new HashMap<>(); while (tokenizer.hasMore()) { tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); tokenizer.consumeCharacter(';'); tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); String attribute = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('='); final String value; if ('"' == tokenizer.previewChar()) { tokenizer.consumeCharacter('"'); StringBuilder valueBuilder = new StringBuilder(); while ('"' != tokenizer.previewChar()) { if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER)); } } value = valueBuilder.toString(); tokenizer.consumeCharacter('"'); } else { value = tokenizer.consumeToken(TOKEN_MATCHER); } parameters.put(attribute, value); } return create(type, subtype, parameters); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + "'", e); } } private  MediaType(String type, String subtype); private  MediaType(Builder builder); static MediaType create(String type, String subtype); static MediaType parse(String input); static Builder builder(); String type(); boolean isWildcardType(); String subtype(); boolean isWildcardSubtype(); Map<String, String> parameters(); MediaType withCharset(String charset); Optional<String> charset(); @Override double qualityFactor(); @Override boolean test(MediaType other); @SuppressWarnings("UnnecessaryJavaDocLink") @Override boolean equals(Object obj); @SuppressWarnings("UnnecessaryJavaDocLink") @Override int hashCode(); @Override String toString(); boolean hasSuffix(String suffix); }
MediaType implements AcceptPredicate<MediaType> { public static MediaType parse(String input) { Objects.requireNonNull(input, "Parameter 'input' is null!"); Tokenizer tokenizer = new Tokenizer(input); try { String type = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('/'); String subtype = tokenizer.consumeToken(TOKEN_MATCHER); Map<String, String> parameters = new HashMap<>(); while (tokenizer.hasMore()) { tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); tokenizer.consumeCharacter(';'); tokenizer.consumeTokenIfPresent(LINEAR_WHITE_SPACE); String attribute = tokenizer.consumeToken(TOKEN_MATCHER); tokenizer.consumeCharacter('='); final String value; if ('"' == tokenizer.previewChar()) { tokenizer.consumeCharacter('"'); StringBuilder valueBuilder = new StringBuilder(); while ('"' != tokenizer.previewChar()) { if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER)); } } value = valueBuilder.toString(); tokenizer.consumeCharacter('"'); } else { value = tokenizer.consumeToken(TOKEN_MATCHER); } parameters.put(attribute, value); } return create(type, subtype, parameters); } catch (IllegalStateException e) { throw new IllegalArgumentException("Could not parse '" + input + "'", e); } } private  MediaType(String type, String subtype); private  MediaType(Builder builder); static MediaType create(String type, String subtype); static MediaType parse(String input); static Builder builder(); String type(); boolean isWildcardType(); String subtype(); boolean isWildcardSubtype(); Map<String, String> parameters(); MediaType withCharset(String charset); Optional<String> charset(); @Override double qualityFactor(); @Override boolean test(MediaType other); @SuppressWarnings("UnnecessaryJavaDocLink") @Override boolean equals(Object obj); @SuppressWarnings("UnnecessaryJavaDocLink") @Override int hashCode(); @Override String toString(); boolean hasSuffix(String suffix); static final String CHARSET_PARAMETER; static final MediaType WILDCARD; static final MediaType APPLICATION_XML; static final MediaType APPLICATION_ATOM_XML; static final MediaType APPLICATION_XHTML_XML; static final MediaType APPLICATION_SVG_XML; static final MediaType APPLICATION_JSON; static final MediaType APPLICATION_STREAM_JSON; static final MediaType APPLICATION_FORM_URLENCODED; static final MediaType MULTIPART_FORM_DATA; static final MediaType APPLICATION_OCTET_STREAM; static final MediaType TEXT_PLAIN; static final MediaType TEXT_XML; static final MediaType TEXT_HTML; static final MediaType APPLICATION_OPENAPI_YAML; static final MediaType APPLICATION_OPENAPI_JSON; static final MediaType APPLICATION_X_YAML; static final MediaType APPLICATION_YAML; static final MediaType TEXT_X_YAML; static final MediaType TEXT_YAML; static final MediaType APPLICATION_JAVASCRIPT; static final Predicate<MediaType> XML_PREDICATE; static final Predicate<MediaType> JSON_PREDICATE; }