@Test public void testFormat () throws Exception { final List <NameValuePair> params = new ArrayList <NameValuePair>(); Assert.assertEquals(0, URLEncodedUtils.format(params, null).length()); params.clear(); params.add(new BasicNameValuePair("Name1", "Value1")); Assert.assertEquals("Name1=Value1", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name2", null)); Assert.assertEquals("Name2=", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value 4!")); Assert.assertEquals("Name4=Value+4%21", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value+4!")); Assert.assertEquals("Name4=Value%2B4%21", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name4", "Value 4! !4")); Assert.assertEquals("Name4=Value+4%21+%214", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name5", "aaa")); params.add(new BasicNameValuePair("Name6", "bbb")); Assert.assertEquals("Name5=aaa&Name6=bbb", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name7", "aaa")); params.add(new BasicNameValuePair("Name7", "b,b")); params.add(new BasicNameValuePair("Name7", "ccc")); Assert.assertEquals("Name7=aaa&Name7=b%2Cb&Name7=ccc", URLEncodedUtils.format(params, null)); params.clear(); params.add(new BasicNameValuePair("Name8", "xx, yy ,zz")); Assert.assertEquals("Name8=xx%2C++yy++%2Czz", URLEncodedUtils.format(params, null)); }
public static String format ( final List <? extends NameValuePair> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), encoding); final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) result.append(PARAMETER_SEPARATOR); result.append(encodedName); result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } return result.toString(); }
URLEncodedUtils { public static String format ( final List <? extends NameValuePair> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), encoding); final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) result.append(PARAMETER_SEPARATOR); result.append(encodedName); result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } return result.toString(); } }
URLEncodedUtils { public static String format ( final List <? extends NameValuePair> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), encoding); final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) result.append(PARAMETER_SEPARATOR); result.append(encodedName); result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } return result.toString(); }  }
URLEncodedUtils { public static String format ( final List <? extends NameValuePair> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), encoding); final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) result.append(PARAMETER_SEPARATOR); result.append(encodedName); result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } return result.toString(); }  static List <NameValuePair> parse(final URI uri, final String encoding); static List <NameValuePair> parse(
            final HttpEntity entity); static boolean isEncoded(final HttpEntity entity); static void parse(
            final List <NameValuePair> parameters,
            final Scanner scanner,
            final String encoding); static String format(
            final List <? extends NameValuePair> parameters,
            final String encoding); }
URLEncodedUtils { public static String format ( final List <? extends NameValuePair> parameters, final String encoding) { final StringBuilder result = new StringBuilder(); for (final NameValuePair parameter : parameters) { final String encodedName = encode(parameter.getName(), encoding); final String value = parameter.getValue(); final String encodedValue = value != null ? encode(value, encoding) : ""; if (result.length() > 0) result.append(PARAMETER_SEPARATOR); result.append(encodedName); result.append(NAME_VALUE_SEPARATOR); result.append(encodedValue); } return result.toString(); }  static List <NameValuePair> parse(final URI uri, final String encoding); static List <NameValuePair> parse(
            final HttpEntity entity); static boolean isEncoded(final HttpEntity entity); static void parse(
            final List <NameValuePair> parameters,
            final Scanner scanner,
            final String encoding); static String format(
            final List <? extends NameValuePair> parameters,
            final String encoding); static final String CONTENT_TYPE; }