ContentTypeUtil { public static String getContentType(String ext) { FileNameMap map = URLConnection.getFileNameMap(); String ret = map.getContentTypeFor("x." + ext); return ret; } private  ContentTypeUtil(); static String getContentTypeByPath(String ext); static String getContentType(String ext);  }
@Test public void testContentType() { assertEquals("text/html", ContentTypeUtil.getContentType("html")); assertEquals("text/html", ContentTypeUtil.getContentType("htm")); assertEquals("text/plain", ContentTypeUtil.getContentType("txt")); assertNull(ContentTypeUtil.getContentType("notexists")); }