URIBuilder { static void formatQuery(final StringBuilder buf, final Iterable<? extends NameValuePair> params, final Charset charset, final boolean blankAsPlus) { int i = 0; for (final NameValuePair parameter : params) { if (i > 0) { buf.append(QUERY_PARAM_SEPARATOR); } PercentCodec.encode(buf, parameter.getName(), charset, blankAsPlus); if (parameter.getValue() != null) { buf.append(PARAM_VALUE_SEPARATOR); PercentCodec.encode(buf, parameter.getValue(), charset, blankAsPlus); } i++; } } URIBuilder();  URIBuilder(final String string);  URIBuilder(final URI uri);  URIBuilder(final String string, final Charset charset);  URIBuilder(final URI uri, final Charset charset); static URIBuilder localhost(); static URIBuilder loopbackAddress(); URIBuilder setCharset(final Charset charset); Charset getCharset(); URI build(); URIBuilder setScheme(final String scheme); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final NameValuePair... nvps); URIBuilder setSchemeSpecificPart(final String schemeSpecificPart, final List <NameValuePair> nvps); URIBuilder setUserInfo(final String userInfo); @Deprecated URIBuilder setUserInfo(final String username, final String password); URIBuilder setHost(final InetAddress host); URIBuilder setHost(final String host); URIBuilder setHttpHost(final HttpHost httpHost ); URIBuilder setPort(final int port); URIBuilder setPath(final String path); URIBuilder setPathSegments(final String... pathSegments); URIBuilder setPathSegmentsRootless(final String... pathSegments); URIBuilder setPathSegments(final List<String> pathSegments); URIBuilder setPathSegmentsRootless(final List<String> pathSegments); URIBuilder removeQuery(); URIBuilder setParameters(final List <NameValuePair> nvps); URIBuilder addParameters(final List <NameValuePair> nvps); URIBuilder setParameters(final NameValuePair... nvps); URIBuilder addParameter(final String param, final String value); URIBuilder setParameter(final String param, final String value); URIBuilder clearParameters(); URIBuilder setCustomQuery(final String query); URIBuilder setFragment(final String fragment); boolean isAbsolute(); boolean isOpaque(); String getScheme(); String getSchemeSpecificPart(); String getUserInfo(); String getHost(); int getPort(); boolean isPathEmpty(); List<String> getPathSegments(); String getPath(); boolean isQueryEmpty(); List<NameValuePair> getQueryParams(); String getFragment(); @Override String toString();  }
@Test public void testFormatQuery() throws Exception { MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name0", null)), CoreMatchers.equalTo("Name0")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name1", "Value1")), CoreMatchers.equalTo("Name1=Value1")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name2", "")), CoreMatchers.equalTo("Name2=")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name4", "Value 4&")), CoreMatchers.equalTo("Name4=Value%204%26")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name4", "Value+4&")), CoreMatchers.equalTo("Name4=Value%2B4%26")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name4", "Value 4& =4")), CoreMatchers.equalTo("Name4=Value%204%26%20%3D4")); MatcherAssert.assertThat(formatQuery( new BasicNameValuePair("Name5", "aaa"), new BasicNameValuePair("Name6", "bbb")), CoreMatchers.equalTo("Name5=aaa&Name6=bbb")); MatcherAssert.assertThat(formatQuery( new BasicNameValuePair("Name7", "aaa"), new BasicNameValuePair("Name7", "b,b"), new BasicNameValuePair("Name7", "ccc") ), CoreMatchers.equalTo("Name7=aaa&Name7=b%2Cb&Name7=ccc")); MatcherAssert.assertThat(formatQuery(new BasicNameValuePair("Name8", "xx, yy ,zz")), CoreMatchers.equalTo("Name8=xx%2C%20%20yy%20%20%2Czz")); MatcherAssert.assertThat(formatQuery( new BasicNameValuePair("russian", RU_HELLO), new BasicNameValuePair("swiss", CH_HELLO)), CoreMatchers.equalTo("russian=" + PercentCodec.encode(RU_HELLO, StandardCharsets.UTF_8) + "&swiss=" + PercentCodec.encode(CH_HELLO, StandardCharsets.UTF_8))); }