EncodeUtil { public static String urlEncode(String toEncode) { String encoded; try { encoded = URLEncoder.encode(toEncode, ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } encoded = encoded.replaceAll("[+]", "%20"); encoded = encoded.replaceAll("%2F", "/"); return encoded; } private  EncodeUtil(); static String urlEncode(String toEncode); static String urlDecode(String toDecode); static final String ENCODING; }
@Test public void testUrlEncode() throws Exception { for (int i = 0; i < chars.length; i++) { assertEquals("Test encoding '" + chars[i] + "'", encoded[i], EncodeUtil.urlEncode(chars[i])); } }