mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8322166: Files.isReadable/isWritable/isExecutable expensive when file does not exist
Reviewed-by: alanb
This commit is contained in:
parent
0f8e4e0a81
commit
51be857f3c
6 changed files with 98 additions and 50 deletions
|
@ -80,6 +80,7 @@ import java.util.stream.StreamSupport;
|
|||
import jdk.internal.util.ArraysSupport;
|
||||
import sun.nio.ch.FileChannelImpl;
|
||||
import sun.nio.cs.UTF_8;
|
||||
import sun.nio.fs.AbstractFileSystemProvider;
|
||||
|
||||
/**
|
||||
* This class consists exclusively of static methods that operate on files,
|
||||
|
@ -2609,7 +2610,11 @@ public final class Files {
|
|||
* is invoked to check read access to the file.
|
||||
*/
|
||||
public static boolean isReadable(Path path) {
|
||||
return isAccessible(path, AccessMode.READ);
|
||||
FileSystemProvider provider = provider(path);
|
||||
if (provider instanceof AbstractFileSystemProvider afsp)
|
||||
return afsp.isReadable(path);
|
||||
else
|
||||
return isAccessible(path, AccessMode.READ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2640,7 +2645,11 @@ public final class Files {
|
|||
* is invoked to check write access to the file.
|
||||
*/
|
||||
public static boolean isWritable(Path path) {
|
||||
return isAccessible(path, AccessMode.WRITE);
|
||||
FileSystemProvider provider = provider(path);
|
||||
if (provider instanceof AbstractFileSystemProvider afsp)
|
||||
return afsp.isWritable(path);
|
||||
else
|
||||
return isAccessible(path, AccessMode.WRITE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2675,7 +2684,11 @@ public final class Files {
|
|||
* checkExec} is invoked to check execute access to the file.
|
||||
*/
|
||||
public static boolean isExecutable(Path path) {
|
||||
return isAccessible(path, AccessMode.EXECUTE);
|
||||
FileSystemProvider provider = provider(path);
|
||||
if (provider instanceof AbstractFileSystemProvider afsp)
|
||||
return afsp.isExecutable(path);
|
||||
else
|
||||
return isAccessible(path, AccessMode.EXECUTE);
|
||||
}
|
||||
|
||||
// -- Recursive operations --
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue