URIUtils implements Cloneable { public static StringBuilder encodeString(StringBuilder buf, String path, String encode) { if (buf == null) { for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '%' || encode.indexOf(c) >= 0) { buf = new StringBuilder(path.length() << 1); break; } } if (buf == null) return null; } for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '%' || encode.indexOf(c) >= 0) { buf.append('%'); StringUtils.append(buf, (byte) (0xff & c), 16); } else buf.append(c); } return buf; } private  URIUtils(); static String encodePath(String path); static StringBuilder encodePath(StringBuilder buf, String path); static String encodeSpaces(String str); @SuppressWarnings("Duplicates") static String encodeSpecific(String str, String charsToEncode); @SuppressWarnings("Duplicates") static String decodeSpecific(String str, String charsToDecode); static StringBuilder encodeString(StringBuilder buf,
                                             String path,
                                             String encode); static String decodePath(String path); static String decodePath(String path, int offset, int length); static String addEncodedPaths(String p1, String p2); static String addPaths(String p1, String p2); static String parentPath(String p); static String canonicalPath(String path); static String canonicalEncodedPath(String path); static String compactPath(String path); static boolean hasScheme(String uri); static String newURI(String scheme, String server, int port, String path, String query); static StringBuilder newURIBuilder(String scheme, String server, int port); static void appendSchemeHostPort(StringBuilder url, String scheme, String server, int port); static void appendSchemeHostPort(StringBuffer url, String scheme, String server, int port); static boolean equalsIgnoreEncodings(String uriA, String uriB); static boolean equalsIgnoreEncodings(URI uriA, URI uriB); static URI addPath(URI uri, String path); static URI getJarSource(URI uri); static String getJarSource(String uri); static final String SLASH; static final String HTTP; static final String HTTPS; static final Charset __CHARSET; }
@Test void testEncodeString() { StringBuilder buf = new StringBuilder(); buf.setLength(0); URIUtils.encodeString(buf, "foo%23;,:=b a r", ";,= "); assertEquals("foo%2523%3b%2c:%3db%20a%20r", buf.toString()); }