@Test public void testValueOf() { MediaType mediaType = MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED); String type = "application/x-www-form-urlencoded"; String charset = "UTF-8"; assertEquals(type, mediaType.getType()); assertEquals(charset, mediaType.getCharset()); assertEquals(MediaType.APPLICATION_FORM_URLENCODED, mediaType.toString()); }
public static MediaType valueOf(String contentType) { if (StringUtils.isEmpty(contentType)) { throw new IllegalArgumentException("MediaType must not be empty"); } String[] values = contentType.split(";"); String charset = Constants.ENCODE; for (String value : values) { if (value.startsWith("charset=")) { charset = value.substring("charset=".length()); } } return new MediaType(values[0], charset); }
MediaType { public static MediaType valueOf(String contentType) { if (StringUtils.isEmpty(contentType)) { throw new IllegalArgumentException("MediaType must not be empty"); } String[] values = contentType.split(";"); String charset = Constants.ENCODE; for (String value : values) { if (value.startsWith("charset=")) { charset = value.substring("charset=".length()); } } return new MediaType(values[0], charset); } }
MediaType { public static MediaType valueOf(String contentType) { if (StringUtils.isEmpty(contentType)) { throw new IllegalArgumentException("MediaType must not be empty"); } String[] values = contentType.split(";"); String charset = Constants.ENCODE; for (String value : values) { if (value.startsWith("charset=")) { charset = value.substring("charset=".length()); } } return new MediaType(values[0], charset); } private  MediaType(String type, String charset); }
MediaType { public static MediaType valueOf(String contentType) { if (StringUtils.isEmpty(contentType)) { throw new IllegalArgumentException("MediaType must not be empty"); } String[] values = contentType.split(";"); String charset = Constants.ENCODE; for (String value : values) { if (value.startsWith("charset=")) { charset = value.substring("charset=".length()); } } return new MediaType(values[0], charset); } private  MediaType(String type, String charset); static MediaType valueOf(String contentType); static MediaType valueOf(String contentType, String charset); String getType(); String getCharset(); @Override String toString(); }
MediaType { public static MediaType valueOf(String contentType) { if (StringUtils.isEmpty(contentType)) { throw new IllegalArgumentException("MediaType must not be empty"); } String[] values = contentType.split(";"); String charset = Constants.ENCODE; for (String value : values) { if (value.startsWith("charset=")) { charset = value.substring("charset=".length()); } } return new MediaType(values[0], charset); } private  MediaType(String type, String charset); static MediaType valueOf(String contentType); static MediaType valueOf(String contentType, String charset); String getType(); String getCharset(); @Override String toString(); static final String APPLICATION_ATOM_XML; static final String APPLICATION_FORM_URLENCODED; static final String APPLICATION_OCTET_STREAM; static final String APPLICATION_SVG_XML; static final String APPLICATION_XHTML_XML; static final String APPLICATION_XML; static final String APPLICATION_JSON; static final String MULTIPART_FORM_DATA; static final String TEXT_HTML; static final String TEXT_PLAIN; }