FlattrConnection implements Connection { protected Charset getCharset(String contentType) { Charset charset = Charset.forName(ENCODING); if (contentType != null) { Matcher m = CHARSET.matcher(contentType); if (m.matches()) { try { charset = Charset.forName(m.group(1)); } catch (UnsupportedCharsetException ex) { LOG.debug(m.group(1), ex); } } } return charset; } FlattrConnection(RequestType type); @Override Connection url(String url); @Override Connection call(String call); @Override Connection token(AccessToken token); @Override Connection key(ConsumerKey key); @Override Connection parameter(String name, String value); @Override Connection parameterArray(String name, String[] value); @Override Connection query(String name, String value); @Override Connection data(FlattrObject data); @Override Connection form(String name, String value); @Override Connection rateLimit(RateLimit limit); @Override Collection<FlattrObject> result(); @Override FlattrObject singleResult();  }
@Test public void charsetTest() { Charset utf8 = Charset.forName("utf-8"); Charset iso_8859_15 = Charset.forName("iso-8859-15"); FlattrConnection conn = new FlattrConnection(RequestType.GET); assertThat(conn.getCharset(null), is(utf8)); assertThat(conn.getCharset(""), is(utf8)); assertThat(conn.getCharset("text/html"), is(utf8)); assertThat(conn.getCharset("text/html; charset=utf-8"), is(utf8)); assertThat(conn.getCharset("text/html; charset=iso-8859-15"), is(iso_8859_15)); assertThat(conn.getCharset("text/html; charset=iso-8859-15; foo=yes"), is(iso_8859_15)); assertThat(conn.getCharset("TEXT/HTML; CHARSET=ISO-8859-15"), is(iso_8859_15)); assertThat(conn.getCharset("text/html; charset=\"iso-8859-15\""), is(iso_8859_15)); assertThat(conn.getCharset("text/html ; charset=\"iso-8859-15\" ; foo=yes"), is(iso_8859_15)); assertThat(conn.getCharset("text/html; charset=UnKnOwN"), is(utf8)); }