EncodingUtils { public static String encodePathWithUTF8(String path) { try { StringBuilder result = new StringBuilder(); for (char each : path.toCharArray()) { if (each == '/') { result.append("/"); } else { result.append(URLEncoder.encode(String.valueOf(each), "UTF-8")); } } return result.toString(); } catch (UnsupportedEncodingException e) { throw processException(e); } }  static String getAutoDecodedString(byte[] data, String defaultEncoding); static String detectEncoding(byte[] data, String defaultEncoding); static String encodePathWithUTF8(String path); static String decodePathWithUTF8(String path);  }
@Test public void testPathEncoding() { assertThat(EncodingUtils.encodePathWithUTF8("hello"), is("hello")); assertThat(EncodingUtils.encodePathWithUTF8("한국"), is("%ED%95%9C%EA%B5%AD")); assertThat(EncodingUtils.encodePathWithUTF8("hello/한국"), is("hello/%ED%95%9C%EA%B5%AD")); assertThat(EncodingUtils.encodePathWithUTF8("hello/한국/와우"), is("hello/%ED%95%9C%EA%B5%AD/%EC%99%80%EC%9A%B0")); assertThat(EncodingUtils.encodePathWithUTF8("--hello/한국/와우/"), is("--hello/%ED%95%9C%EA%B5%AD/%EC%99%80%EC%9A%B0/")); assertThat(EncodingUtils.encodePathWithUTF8("/hello/한국/와우/"), is("/hello/%ED%95%9C%EA%B5%AD/%EC%99%80%EC%9A%B0/")); assertThat(EncodingUtils.encodePathWithUTF8("/hello/한국.-/와우/"), is("/hello/%ED%95%9C%EA%B5%AD.-/%EC%99%80%EC%9A%B0/")); }