private static boolean checkCaseCanonical ( final File file , String pathToTest ) throws PrivilegedActionException { // The canonical path returns the actual path on the file system so get this String onDiskCanonicalPath = AccessController . doPrivileged ( new PrivilegedExceptionAction < String > ( ) { /** {@inheritDoc} */ @ Override public String run ( ) throws IOException { return file . getCanonicalPath ( ) ; } } ) ; onDiskCanonicalPath = onDiskCanonicalPath . replace ( "\\" , "/" ) ; // The trailing / on a file name is optional so add it if this is a directory final String expectedEnding ; if ( onDiskCanonicalPath . endsWith ( "/" ) ) { if ( pathToTest . endsWith ( "/" ) ) { expectedEnding = pathToTest ; } else { expectedEnding = pathToTest + "/" ; } } else { if ( pathToTest . endsWith ( "/" ) ) { expectedEnding = pathToTest . substring ( 0 , pathToTest . length ( ) - 1 ) ; } else { expectedEnding = pathToTest ; } } if ( expectedEnding . isEmpty ( ) ) { // Nothing to compare so case must match return true ; } return onDiskCanonicalPath . endsWith ( expectedEnding ) ; }
Test that the path to a file matches a specified path .