RepositoryFilenameUtils { public static String escape( final String name, final List<Character> reservedChars ) { if ( name == null || reservedChars == null ) { throw new IllegalArgumentException(); } if ( reservedChars.contains( escapeChar ) ) { throw new IllegalArgumentException(); } List<Character> mergedReservedChars = new ArrayList<Character>( reservedChars ); mergedReservedChars.add( escapeChar ); StringBuilder buffer = new StringBuilder( name.length() * 2 ); for ( int i = 0; i < name.length(); i++ ) { char ch = name.charAt( i ); if ( mergedReservedChars.contains( ch ) ) { buffer.append( escapeChar ); buffer.append( Character.toUpperCase( Character.forDigit( ch / 16, 16 ) ) ); buffer.append( Character.toUpperCase( Character.forDigit( ch % 16, 16 ) ) ); } else { buffer.append( ch ); } } return buffer.toString(); } private  RepositoryFilenameUtils(); static String normalize( final String filename ); static String normalize( final String filename, final boolean leadingSlash ); static String normalizeNoEndSeparator( final String filename ); static String concat( final String basePath, final String fullFilenameToAdd ); static String separatorsToRepository( final String path ); static int getPrefixLength( final String filename ); static int indexOfLastSeparator( final String filename ); static int indexOfExtension( final String filename ); static String getPrefix( final String filename ); static String getPath( final String filename ); static String getPathNoEndSeparator( final String filename ); static String getFullPath( final String filename ); static String getFullPathNoEndSeparator( final String filename ); static String getName( final String filename ); static String getBaseName( final String filename ); static String getExtension( final String filename ); static String removeExtension( final String filename ); static boolean equals( final String filename1, final String filename2 ); static boolean equalsNormalized( String filename1, String filename2 ); static boolean isExtension( final String filename, final String extension ); static boolean isExtension( final String filename, final String[] extensions ); static boolean isExtension( final String filename, final Collection extensions ); static boolean wildcardMatch( final String filename, final String wildcardMatcher ); static String escape( final String name, final List<Character> reservedChars ); static String unescape( final String name );  }
@Test public void testEscape() { List<Character> emptyList = Collections.emptyList(); try { RepositoryFilenameUtils.escape( null, emptyList ); fail(); } catch ( IllegalArgumentException e ) { } try { RepositoryFilenameUtils.escape( "hello", null ); fail(); } catch ( IllegalArgumentException e ) { } assertEquals( "hello", RepositoryFilenameUtils.escape( "hello", emptyList ) ); assertEquals( "hello", RepositoryFilenameUtils.escape( "hello", Arrays.asList( new Character[] { '/' } ) ) ); assertEquals( "h%65llo", RepositoryFilenameUtils.escape( "hello", Arrays.asList( new Character[] { 'e' } ) ) ); assertEquals( "hel%25lo", RepositoryFilenameUtils.escape( "hel%lo", emptyList ) ); assertEquals( "helloン", RepositoryFilenameUtils.escape( "helloン", emptyList ) ); }