HTTP { public static Optional<String> charsetFromContentType(String s) { if (s.indexOf("charset=") == -1) { return Optional.absent(); } else { return Optional.of(s.substring(s.indexOf("charset=") + "charset=".length())); } }  static Optional<String> getContentTypeFromExtension(String filename); static boolean isTextContentType(String contentType); static Optional<String> charsetFromContentType(String s); static String headerTokenCompatible(String s, String specialCharsReplacement);  }
@Test public void should_extract_charset() throws Exception { assertThat(HTTP.charsetFromContentType("text/html; charset=UTF-8")).isEqualTo(Optional.of("UTF-8")); assertThat(HTTP.charsetFromContentType("application/json; charset=ISO-8859-1")).isEqualTo(Optional.of("ISO-8859-1")); assertThat(HTTP.charsetFromContentType("application/json")).isEqualTo(Optional.<String>absent()); }