public static final void checkFileType ( Path path , String perms ) { if ( perms . length ( ) != 10 ) { throw new IllegalArgumentException ( perms + " not permission. E.g. -rwxr--r--" ) ; } switch ( perms . charAt ( 0 ) ) { case ' ' : if ( ! Files . isRegularFile ( path ) ) { throw new IllegalArgumentException ( "file is not regular file" ) ; } break ; case ' ' : if ( ! Files . isDirectory ( path ) ) { throw new IllegalArgumentException ( "file is not directory" ) ; } break ; case ' ' : if ( ! Files . isSymbolicLink ( path ) ) { throw new IllegalArgumentException ( "file is not symbolic link" ) ; } break ; default : throw new UnsupportedOperationException ( perms + " not supported" ) ; } }
Throws IllegalArgumentException if perms length ! = 10 or files type doesn t match with permission .