@Test public void normalizeWithNotPrintableChars() throws Exception { final String TEST_NAME = new String( new char[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, '.', 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 } ); final String EXPECTED_NAME = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F" + "." + "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"; 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; }