UrlUtils { public static String percentEncode(String s) { if (s == null) { return ""; } final StringBuilder sb = new StringBuilder(); final String encoded = UrlUtils.urlEncode(s); final int encodedLength = encoded.length(); for (int i = 0; i < encodedLength; i++) { final char c = encoded.charAt(i); if (c == '*') { sb.append("%2A"); } else if (c == '+') { sb.append("%20"); } else if (c == '%' && (i + 2) < encodedLength && encoded.charAt(i + 1) == '7' && encoded.charAt(i + 2) == 'E') { sb.append('~'); i += 2; } else { sb.append(c); } } return sb.toString(); } private  UrlUtils(); static TreeMap<String, String> getQueryParams(URI uri, boolean decode); static TreeMap<String, String> getQueryParams(String paramsString, boolean decode); static String urlEncode(String s); static String urlDecode(String s); static String percentEncode(String s); static final String UTF8; }
@Test public void testPercentEncode() { int i = 0; for (String s : ORIGINAL_STRINGS) { assertEquals(PERCENT_ENCODED_STRINGS[i], UrlUtils.percentEncode(s)); i += 1; } }