EncodingUtils { public static String encodeUrl(final String url) { return PLUS_SIGN_PATTERN.matcher(FORWARD_SLASH_PATTERN.matcher(encode(url)).replaceAll("/")).replaceAll("%20"); } private  EncodingUtils(); static String encode(final String str); static String encodeUrl(final String url); static String encodeUri(final String uri); static String encodeFilename(final String filename, final String userAgent);  }
@Test public void testEncodeUrl() throws Exception { assertEquals("/test/%C3%BC.txt", EncodingUtils.encodeUrl("/test/\u00fc.txt")); assertEquals("/%C3%A5%C3%A4%C3%B6.txt", EncodingUtils.encodeUrl("/\u00e5\u00e4\u00f6.txt")); assertEquals("/%2B/test.txt", EncodingUtils.encodeUrl("/+/test.txt")); assertEquals("/%23/test.txt", EncodingUtils.encodeUrl("/#/test.txt")); assertEquals("%20", EncodingUtils.encodeUrl(" ")); assertEquals("", EncodingUtils.encodeUrl("")); try { EncodingUtils.encodeUrl(null); fail("Should cause NPE"); } catch (Exception e) { } }