ExportFileNameEncoder { public static String encodeZipPathName( String path ) { String[] folders = path.split( "/" ); StringBuilder encodedPath = new StringBuilder( path.length() * 2 ); for ( int i = 0; i < folders.length; i++ ) { encodedPath.append( encodeZipFileName( folders[i] ) ); if ( i != folders.length - 1 || path.endsWith( "/" ) ) { encodedPath.append( "/" ); } } return encodedPath.toString(); }  static String encodeZipFileName( String fileName ); static String decodeZipFileName( String encodedFileName ); static String encodeZipPathName( String path ); static String decodeZipPath( String encodedPath );  }
@Test public void testEncodeZipPathName() { assertEquals( "", ExportFileNameEncoder.encodeZipPathName( "" ) ); assertEquals( "", ExportFileNameEncoder.encodeZipPathName( "/" ) ); assertEquals( ".", ExportFileNameEncoder.encodeZipPathName( "." ) ); assertEquals( "./..", ExportFileNameEncoder.encodeZipPathName( "./.." ) ); assertEquals( "root.dir/mean+dir/leaf+dir_specials%3A%28%2B%29%25%5E", ExportFileNameEncoder.encodeZipPathName( "root.dir/mean dir/leaf dir_specials:(+)%^" ) ); assertEquals( "/root.dir/mean+dir/leaf+dir_specials%3A%28%2B%29%25%5E", ExportFileNameEncoder.encodeZipPathName( "/root.dir/mean dir/leaf dir_specials:(+)%^" ) ); assertEquals( "root.dir/mean+dir/leaf+dir_specials%3A%28%2B%29%25%5E/", ExportFileNameEncoder.encodeZipPathName( "root.dir/mean dir/leaf dir_specials:(+)%^/" ) ); assertEquals( "/root.dir/mean+dir/leaf+dir_specials%3A%28%2B%29%25%5E/", ExportFileNameEncoder.encodeZipPathName( "/root.dir/mean dir/leaf dir_specials:(+)%^/" ) ); }