mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8283335: Add exists and readAttributesIfExists methods to FileSystemProvider
Reviewed-by: alanb
This commit is contained in:
parent
c45d613faa
commit
d48694d0f3
13 changed files with 577 additions and 175 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -27,7 +27,6 @@ package sun.nio.fs;
|
|||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
@ -110,51 +109,6 @@ public abstract class AbstractFileSystemProvider extends FileSystemProvider {
|
|||
return implDelete(file, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a file is a directory.
|
||||
*
|
||||
* @return {@code true} if the file is a directory; {@code false} if
|
||||
* the file does not exist, is not a directory, or it cannot
|
||||
* be determined if the file is a directory or not.
|
||||
*/
|
||||
public boolean isDirectory(Path file) {
|
||||
try {
|
||||
return readAttributes(file, BasicFileAttributes.class).isDirectory();
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether a file is a regular file with opaque content.
|
||||
*
|
||||
* @return {@code true} if the file is a regular file; {@code false} if
|
||||
* the file does not exist, is not a regular file, or it
|
||||
* cannot be determined if the file is a regular file or not.
|
||||
*/
|
||||
public boolean isRegularFile(Path file) {
|
||||
try {
|
||||
return readAttributes(file, BasicFileAttributes.class).isRegularFile();
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a file.
|
||||
*
|
||||
* @return {@code true} if the file exists; {@code false} if the file does
|
||||
* not exist or its existence cannot be determined.
|
||||
*/
|
||||
public boolean exists(Path file) {
|
||||
try {
|
||||
checkAccess(file);
|
||||
return true;
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a path name as bytes for a Unix domain socket.
|
||||
* Different encodings may be used for these names on some platforms.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue