EncodingUtils { public static String encodeUri(final String uri) { try { return new URI(null, null, uri, null).toASCIIString(); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } 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 testEncodeUri() throws Exception { assertEquals("/test/%C3%BC.txt", EncodingUtils.encodeUri("/test/\u00fc.txt")); assertEquals("/%C3%A5%C3%A4%C3%B6.txt", EncodingUtils.encodeUri("/\u00e5\u00e4\u00f6.txt")); assertEquals("/+/test.txt", EncodingUtils.encodeUri("/+/test.txt")); assertEquals("/%23/test.txt", EncodingUtils.encodeUri("/#/test.txt")); assertEquals("%20", EncodingUtils.encodeUri(" ")); assertEquals("", EncodingUtils.encodeUri("")); assertEquals("", EncodingUtils.encodeUri(null)); }