UrlEncoded extends MultiMap<String> implements Cloneable { public static void decodeTo(String content, MultiMap<String> map, String charset) { decodeTo(content, map, charset == null ? null : Charset.forName(charset)); } UrlEncoded(UrlEncoded url);  UrlEncoded();  UrlEncoded(String query); static String encode(MultiMap<String> map, Charset charset, boolean equalsForNullValue); static void decodeTo(String content, MultiMap<String> map, String charset); static void decodeTo(String content, MultiMap<String> map, Charset charset); static void decodeUtf8To(String query, MultiMap<String> map); static void decodeUtf8To(String query, int offset, int length, MultiMap<String> map); static void decode88591To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys); static void decodeUtf8To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys); static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys); static void decodeTo(InputStream in, MultiMap<String> map, String charset, int maxLength, int maxKeys); static void decodeTo(InputStream in, MultiMap<String> map, Charset charset, int maxLength, int maxKeys); static String decodeString(String encoded); static String decodeString(String encoded, int offset, int length, Charset charset); static String encodeString(String string); static String encodeString(String string, Charset charset); void decode(String query); void decode(String query, Charset charset); String encode(); String encode(Charset charset); String encode(Charset charset, boolean equalsForNullValue); @Override Object clone(); static final Charset ENCODING; }
@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"}, }; 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); }