@Test public void testNameValueUrlEncodeMultipleParamsUrlEncodeFalse() throws Exception { String queryParams = "p ar%20am+1=The+string+%40foo-bar"; List<? extends NameValuePair> encodeQueryParams = Utils.urlEncodeMultipleParams(queryParams, false); assertEquals("p ar am 1", encodeQueryParams.get(0).getName()); assertEquals("The string @foo-bar", encodeQueryParams.get(0).getValue()); queryParams = "p ar%20am+1=The%20st+ring %40foo-bar"; encodeQueryParams = Utils.urlEncodeMultipleParams(queryParams, false); assertEquals("p ar am 1", encodeQueryParams.get(0).getName()); assertEquals("The st ring @foo-bar", encodeQueryParams.get(0).getValue()); }
public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET); if (value != null) { value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; }
Utils { public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET); if (value != null) { value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; } }
Utils { public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET); if (value != null) { value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; }  }
Utils { public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET); if (value != null) { value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; }  static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode); static String urlEncodeQueryParams(String params, boolean urlEncode); static int validatePortNumber(String portStringValue); }
Utils { public static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode) throws UrlEncodeException { List<BasicNameValuePair> list = new ArrayList<>(); String[] pairs = params.split("&"); for (String pair : pairs) { String[] nameValue = pair.split("=", 2); String name = nameValue[0]; String value = nameValue.length == 2 ? nameValue[1] : null; if (!urlEncode) { try { name = URLDecoder.decode(name, DEFAULT_CHARACTER_SET); if (value != null) { value = URLDecoder.decode(value, DEFAULT_CHARACTER_SET); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } catch (IllegalArgumentException ie) { throw new UrlEncodeException(ie.getMessage(), ie); } } list.add(new BasicNameValuePair(name, value)); } return list; }  static List<? extends NameValuePair> urlEncodeMultipleParams(String params, boolean urlEncode); static String urlEncodeQueryParams(String params, boolean urlEncode); static int validatePortNumber(String portStringValue); static final String DEFAULT_CHARACTER_SET; }