FileSystemUtils { public static String getCachePrefix( String path ) throws IOException { String suffix = ""; int i = path.lastIndexOf( '.' ), j = path.lastIndexOf( '/' ); if( i > -1 && i > j ) { suffix = path.substring( i ); } StringBuilder sb = new StringBuilder(); for( byte b: md5( path ) ) { String p = Integer.toHexString( Byte.toUnsignedInt( b ) ); if( p.length() == 1 ) { sb.append( '0' ); } sb.append( p ); } String p = sb.toString(); return p.substring( 0, 1 ) + "/" + p.substring( 0, 2 ) + "/" + p + suffix; }  static synchronized String getCacheBase(); static Path getCacheDirectory(); static ScheduledFuture<?> scheduleAtFixedRate( Runnable command, long initialDelay, long period, TimeUnit unit ); static ScheduledFuture<?> schedule( Runnable command, long delay, TimeUnit unit ); static byte[] md5( String s ); static String getMediaWikiPrefix( String path ); static String getOpenDataCMSPrefix( String path ); static String getCachePrefix( String path ); static boolean isTrue( Map<String, ?> env, String name ); static boolean isFalse( Map<String, ?> env, String name ); static String getString( Map<String, ?> env, String key ); static String getString( Map<String, ?> env, String key, String defaultValue ); static String getString( Map<String, ?> env, String key, Supplier<String> defaultValue ); static long getLong( Map<String, ?> env, String key, long defaultValue ); static T get( Map<String, ?> env, String key ); static T get( Map<String, ?> env, String key, Supplier<T> defaultValue ); static final URI getCleanURI( URI uri ); static final URI getFileSystemURI( URI uri ); static final Map<String, ?> getFileSystemEnv( URI uri, Map<String, ?> env ); static long copy( InputStream source, OutputStream sink ); static E getEnum( Class<E> clazz, Map<String, ?> env, String key, E defaultValue ); static void copyFromRemote( IOSupplier<InputStream> src, FileSystemIO io, char[] path ); static final String CACHEBASE_PROPERTY; static final String CACHEBASE_ENV; static final String UTF8; }
@Test public void getCachePrefix() throws IOException { assertEquals( "0/09/098f6bcd4621d373cade4e832627b4f6", FileSystemUtils.getCachePrefix( "test" ) ); assertEquals( "0/07/073402a6e3f1a393222038b31c140998", FileSystemUtils.getCachePrefix( "dir/test" ) ); assertEquals( "0/04/0412c29576c708cf0155e8de242169b1.jpg", FileSystemUtils.getCachePrefix( "test.jpg" ) ); assertEquals( "b/ba/bac3ba4acda45d834747e5b3339f0f1c.png", FileSystemUtils.getCachePrefix( "dir/test.png" ) ); assertEquals( "0/02/021ad58091421abab4be786251454727.jpg", FileSystemUtils.getCachePrefix( "Harry-Green-HampsteadHeath-copy.jpg" ) ); }