HttpHeaderUtils { public static String getCharsetOfContentType(String rawContentType, String defaultEncoding) { if (rawContentType.contains("charset=")) { String charset = rawContentType.split("charset=") [1]; return charset; } else { return defaultEncoding; } }  static String getContentTypeFromContentTypeAndCharacterSetting(String rawContentType); static String getCharsetOfContentType(String rawContentType, String defaultEncoding); static String getCharsetOfContentTypeOrUtf8(String rawContentType);  }
@Test public void testGetCharacterSetOfContentType() { assertEquals("utf-8", HttpHeaderUtils.getCharsetOfContentType("application/json; charset=utf-8", "TEST_ENCODING")); assertEquals("utf-8", HttpHeaderUtils.getCharsetOfContentType("application/json;charset=utf-8", "TEST_ENCODING")); assertEquals("TEST_ENCODING", HttpHeaderUtils.getCharsetOfContentType("application/json", "TEST_ENCODING")); }
@Test public void testGetCharacterSetOfContentTypeOrUtf8() { assertEquals("TEST_ENCODING", HttpHeaderUtils.getCharsetOfContentType("application/json; charset=TEST_ENCODING", NinjaConstant.UTF_8)); assertEquals("TEST_ENCODING", HttpHeaderUtils.getCharsetOfContentType("application/json;charset=TEST_ENCODING", "TEST_ENCODING")); assertEquals(NinjaConstant.UTF_8, HttpHeaderUtils.getCharsetOfContentType("application/json", NinjaConstant.UTF_8)); }