MediaType implements Comparable<MediaType>, Serializable { public String toString() { return string; } MediaType(
            String type, String subtype, Map<String, String> parameters);  MediaType(String type, String subtype); private  MediaType(String string, int slash);  MediaType(MediaType type, Map<String, String> parameters);  MediaType(MediaType type, String name, String value);  MediaType(MediaType type, Charset charset); static MediaType application(String type); static MediaType audio(String type); static MediaType image(String type); static MediaType text(String type); static MediaType video(String type); static Set<MediaType> set(MediaType... types); static Set<MediaType> set(String... types); static MediaType parse(String string); MediaType getBaseType(); String getType(); String getSubtype(); boolean hasParameters(); Map<String, String> getParameters(); String toString(); boolean equals(Object object); int hashCode(); int compareTo(MediaType that); static final MediaType OCTET_STREAM; static final MediaType EMPTY; static final MediaType TEXT_PLAIN; static final MediaType TEXT_HTML; static final MediaType APPLICATION_XML; static final MediaType APPLICATION_ZIP; }
@Test public void testBasics() { assertEquals( "application/octet-stream", new MediaType("application", "octet-stream").toString()); assertEquals( "text/plain", new MediaType("text", "plain").toString()); Map<String, String> parameters = new HashMap<String, String>(); assertEquals( "text/plain", new MediaType("text", "plain", parameters).toString()); parameters.put("charset", "UTF-8"); assertEquals( "text/plain; charset=UTF-8", new MediaType("text", "plain", parameters).toString()); parameters.put("x-eol-style", "crlf"); assertEquals( "text/plain; charset=UTF-8; x-eol-style=crlf", new MediaType("text", "plain", parameters).toString()); }
@Test public void testLowerCase() { assertEquals( "text/plain", new MediaType("TEXT", "PLAIN").toString()); assertEquals( "text/plain", new MediaType("Text", "Plain").toString()); Map<String, String> parameters = new HashMap<String, String>(); assertEquals( "text/plain", new MediaType("text", "PLAIN", parameters).toString()); parameters.put("CHARSET", "UTF-8"); assertEquals( "text/plain; charset=UTF-8", new MediaType("TEXT", "plain", parameters).toString()); parameters.put("X-Eol-Style", "crlf"); assertEquals( "text/plain; charset=UTF-8; x-eol-style=crlf", new MediaType("TeXt", "PlAiN", parameters).toString()); }
@Test public void testTrim() { assertEquals( "text/plain", new MediaType(" text ", " plain ").toString()); assertEquals( "text/plain", new MediaType("\ttext", "plain\t").toString()); Map<String, String> parameters = new HashMap<String, String>(); assertEquals( "text/plain", new MediaType("text\r\n", " \tplain", parameters).toString()); parameters.put(" charset", "UTF-8"); assertEquals( "text/plain; charset=UTF-8", new MediaType("\n\ntext", "plain \r", parameters).toString()); parameters.put("\r\n\tx-eol-style \t", "crlf"); assertEquals( "text/plain; charset=UTF-8; x-eol-style=crlf", new MediaType(" text", "\tplain ", parameters).toString()); }
@Test public void testQuote() { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("a", " value with spaces "); parameters.put("b", "text/plain"); parameters.put("c", "()<>@,;:\\\"/[]?="); assertEquals( "text/plain; a=\" value with spaces \"; b=\"text\\/plain\"" + "; c=\"\\(\\)\\<\\>\\@\\,\\;\\:\\\\\\\"\\/\\[\\]\\?\\=\"", new MediaType("text", "plain", parameters).toString()); }