RFR: 8283335 : Add exists and readAttributesIfExists methods to FileSystemProvider
Brian Burkhalter
bpb at openjdk.org
Wed Jun 22 22:21:42 UTC 2022
On Wed, 22 Jun 2022 19:05:41 GMT, Lance Andersen <lancea at openjdk.org> wrote:
> Hi,
>
> Please review the following patch which will:
>
> - Enhance the java.nio.file.spi.FileSystemProvider abstract class to include the methods
>
> - public boolean exists(Path path, LinkOption... options)
> - public <A extends BasicFileAttributes> A readAttributesIfExists(Path path, Class<A> type, LinkOption... options)
>
>
> This change allows for providers to provide optimizations when the file's attributes are not needed.
>
> Mach5 tiers 1 - 3 run clean with this change
>
> The CSR may be viewed at [JDK-8283336](https://bugs.openjdk.org/browse/JDK-8283336)
>
>
> Best,
> Lance
src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 80:
> 78: static UnixFileAttributes getIfExists(UnixPath path) throws UnixException {
> 79: UnixFileAttributes attrs = new UnixFileAttributes();
> 80: int errno = UnixNativeDispatcher.stat2(path, attrs);
I think that this is the only use of `stat2()`. It could be deleted if this method were replaced with this:
static UnixFileAttributes getIfExists(UnixPath path) throws UnixException {
UnixFileAttributes attrs = new UnixFileAttributes();
try {
UnixNativeDispatcher.stat(path, attrs);
return attrs;
} catch (UnixException e) {
if (e.errno() == UnixConstants.ENOENT) {
return null;
}
throw e;
}
}
-------------
PR: https://git.openjdk.org/jdk/pull/9249
More information about the core-libs-dev
mailing list