@Test
void testUrlEncodedStream()
        throws Exception {

    String[][] charsets = new String[][]
            {
                    {__UTF8, null, "%30"},
                    {__ISO_8859_1, __ISO_8859_1, "%30"},
                    {__UTF8, __UTF8, "%30"},
                    {__UTF16, __UTF16, "%00%30"},
            };
    // Note: "%30" -> decode -> "0"
    for (int i = 0; i < charsets.length; i++) {
        ByteArrayInputStream in = new ByteArrayInputStream(("name\n=value+" + charsets[i][2] + "&name1=&name2&n\u00e3me3=value+3").getBytes(charsets[i][0]));
        MultiMap<String> m = new MultiMap<>();
        UrlEncoded.decodeTo(in, m, charsets[i][1] == null ? null : Charset.forName(charsets[i][1]), -1, -1);
        assertEquals(4, m.size());
        assertEquals("value 0", m.getString("name\n"));
        assertEquals("", m.getString("name1"));
        assertEquals("", m.getString("name2"));
        assertEquals("value 3", m.getString("n\u00e3me3"));
    }
    if (Charset.isSupported("Shift_JIS")) {
        ByteArrayInputStream in2 = new ByteArrayInputStream("name=%83e%83X%83g".getBytes(StandardCharsets.ISO_8859_1));
        MultiMap<String> m2 = new MultiMap<>();
        UrlEncoded.decodeTo(in2, m2, Charset.forName("Shift_JIS"), -1, -1);
        assertEquals(1, m2.size());
        assertEquals("\u30c6\u30b9\u30c8", m2.getString("name"));
    } else
        assertTrue(true);
}