OAuth { public static <T extends Map.Entry<String, String>> void formEncode(Collection<T> parameters, OutputStream into) throws IOException { if (parameters != null) { boolean first = true; for (Map.Entry<String, String> entry : parameters) { if (first) { first = false; } else { into.write('&'); } into.write(percentEncode(safeToString(entry.getKey())).getBytes()); into.write('='); into.write(percentEncode(safeToString(entry.getValue())).getBytes()); } } }  static String percentEncode(String s); static String percentDecode(String s); static void formEncode(Collection<T> parameters,
            OutputStream into); static String formEncode(Collection<T> parameters); static HttpParameters decodeForm(String form); static HttpParameters decodeForm(InputStream content); static Map<String, String> toMap(Collection<T> from); static final String safeToString(Object from); static boolean isEmpty(String str); static String addQueryParameters(String url, String... kvPairs); static String addQueryParameters(String url, Map<String, String> params); static String addQueryString(String url, String queryString); static String prepareOAuthHeader(String... kvPairs); static HttpParameters oauthHeaderToParamsMap(String oauthHeader); static String toHeaderElement(String name, String value); static void debugOut(String key, String value); static final String VERSION_1_0; static final String ENCODING; static final String FORM_ENCODED; static final String HTTP_AUTHORIZATION_HEADER; static final String OAUTH_CONSUMER_KEY; static final String OAUTH_TOKEN; static final String OAUTH_TOKEN_SECRET; static final String OAUTH_SIGNATURE_METHOD; static final String OAUTH_SIGNATURE; static final String OAUTH_TIMESTAMP; static final String OAUTH_NONCE; static final String OAUTH_VERSION; static final String OAUTH_CALLBACK; static final String OAUTH_CALLBACK_CONFIRMED; static final String OAUTH_VERIFIER; static final String OUT_OF_BAND; }
@Test public void shouldCorrectlyFormEncodeParameters() throws Exception { HashMap<String, String> params = new HashMap<String, String>(); params.put("one", rfc3986ReservedCharacters); params.put(rfc3986ReservedCharacters, rfc3986UnreservedCharacters); assertEquals("one=" + reservedCharactersEncoded + "&" + reservedCharactersEncoded + "=" + rfc3986UnreservedCharacters, OAuth.formEncode(params.entrySet())); }