@Test public void normalizeWithReservedChars() throws Exception { final String TEST_NAME = "?a/b\nc\td\re*f\\g:h<i>j.txt|"; final String EXPECTED_NAME = "%3Fa/b%0Ac%09d%0De%2Af\\g%3Ah%3Ci%3Ej.txt%7C"; assertEquals(EXPECTED_NAME, FilenameUtils.normalize(TEST_NAME)); }
public static String normalize(final String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } StringBuilder sb = new StringBuilder(); for (char c: name.toCharArray()) { if (RESERVED.contains(c)) { sb.append('%').append((c<16) ? "0" : "").append(Integer.toHexString(c).toUpperCase(Locale.ROOT)); } else { sb.append(c); } } return sb.toString(); }
FilenameUtils { public static String normalize(final String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } StringBuilder sb = new StringBuilder(); for (char c: name.toCharArray()) { if (RESERVED.contains(c)) { sb.append('%').append((c<16) ? "0" : "").append(Integer.toHexString(c).toUpperCase(Locale.ROOT)); } else { sb.append(c); } } return sb.toString(); } }
FilenameUtils { public static String normalize(final String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } StringBuilder sb = new StringBuilder(); for (char c: name.toCharArray()) { if (RESERVED.contains(c)) { sb.append('%').append((c<16) ? "0" : "").append(Integer.toHexString(c).toUpperCase(Locale.ROOT)); } else { sb.append(c); } } return sb.toString(); }  }
FilenameUtils { public static String normalize(final String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } StringBuilder sb = new StringBuilder(); for (char c: name.toCharArray()) { if (RESERVED.contains(c)) { sb.append('%').append((c<16) ? "0" : "").append(Integer.toHexString(c).toUpperCase(Locale.ROOT)); } else { sb.append(c); } } return sb.toString(); }  static String normalize(final String name); static String getName(final String path); }
FilenameUtils { public static String normalize(final String name) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); } StringBuilder sb = new StringBuilder(); for (char c: name.toCharArray()) { if (RESERVED.contains(c)) { sb.append('%').append((c<16) ? "0" : "").append(Integer.toHexString(c).toUpperCase(Locale.ROOT)); } else { sb.append(c); } } return sb.toString(); }  static String normalize(final String name); static String getName(final String path); final static char[] RESERVED_FILENAME_CHARACTERS; }