本文整理了Java中java.nio.file.Files.isWritable()
方法的一些代码示例,展示了Files.isWritable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.isWritable()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:isWritable
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isWritable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isWritable() {
return (Files.isWritable(this.path) && !Files.isDirectory(this.path));
}
代码示例来源:origin: org.assertj/assertj-core
public boolean isWritable(Path path) {
return Files.isWritable(path);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.io.File#canWrite()
* @see java.io.File#isDirectory()
*/
@Override
public boolean isWritable() {
return (this.file != null ? this.file.canWrite() && !this.file.isDirectory() :
Files.isWritable(this.filePath) && !Files.isDirectory(this.filePath));
}
代码示例来源:origin: joel-costigliola/assertj-core
public boolean isWritable(Path path) {
return Files.isWritable(path);
}
代码示例来源:origin: org.springframework/spring-core
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.nio.file.Files#isWritable(Path)
* @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...)
*/
@Override
public boolean isWritable() {
return (Files.isWritable(this.path) && !Files.isDirectory(this.path));
}
代码示例来源:origin: org.springframework/spring-core
/**
* This implementation checks whether the underlying file is marked as writable
* (and corresponds to an actual file with content, not to a directory).
* @see java.io.File#canWrite()
* @see java.io.File#isDirectory()
*/
@Override
public boolean isWritable() {
return (this.file != null ? this.file.canWrite() && !this.file.isDirectory() :
Files.isWritable(this.filePath) && !Files.isDirectory(this.filePath));
}
代码示例来源:origin: syncany/syncany
@Override
public boolean testTargetCanCreate() {
if (Files.isWritable(repoPath.getParent())) {
logger.log(Level.INFO, "testTargetCanCreate: Can create target.");
return true;
}
else {
logger.log(Level.INFO, "testTargetCanCreate: Can NOT create target.");
return false;
}
}
}
代码示例来源:origin: oracle/helidon
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
if (!Files.isWritable(path)) {
//When you try to delete the file on Windows and it is marked as read-only
//it would fail unless this change
path.toFile().setWritable(true);
}
Files.delete(path);
return FileVisitResult.CONTINUE;
}
代码示例来源:origin: oracle/helidon
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!Files.isWritable(file)) {
//When you try to delete the file on Windows and it is marked as read-only
//it would fail unless this change
file.toFile().setWritable(true);
}
Files.delete(file);
return FileVisitResult.CONTINUE;
}
代码示例来源:origin: jenkinsci/jenkins
private static void makeRemovable(@Nonnull Path path) throws IOException {
if (!Files.isWritable(path)) {
makeWritable(path);
}
/*
on Unix both the file and the directory that contains it has to be writable
for a file deletion to be successful. (Confirmed on Solaris 9)
$ ls -la
total 6
dr-xr-sr-x 2 hudson hudson 512 Apr 18 14:41 .
dr-xr-sr-x 3 hudson hudson 512 Apr 17 19:36 ..
-r--r--r-- 1 hudson hudson 469 Apr 17 19:36 manager.xml
-rw-r--r-- 1 hudson hudson 0 Apr 18 14:41 x
$ rm x
rm: x not removed: Permission denied
*/
Optional<Path> maybeParent = Optional.ofNullable(path.getParent()).map(Path::normalize).filter(p -> !Files.isWritable(p));
if (maybeParent.isPresent()) {
makeWritable(maybeParent.get());
}
}
代码示例来源:origin: ctripcorp/apollo
private File findLocalCacheDir() {
try {
String defaultCacheDir = m_configUtil.getDefaultLocalCacheDir();
Path path = Paths.get(defaultCacheDir);
if (!Files.exists(path)) {
Files.createDirectories(path);
}
if (Files.exists(path) && Files.isWritable(path)) {
return new File(defaultCacheDir, CONFIG_DIR);
}
} catch (Throwable ex) {
//ignore
}
return new File(ClassLoaderUtil.getClassPath(), CONFIG_DIR);
}
代码示例来源:origin: Alluxio/alluxio
/**
* Checks if a storage directory path is accessible.
*
* @param path the given path
* @return true if path exists, false otherwise
*/
public static boolean isStorageDirAccessible(String path) {
Path filePath = Paths.get(path);
return Files.exists(filePath)
&& Files.isReadable(filePath)
&& Files.isWritable(filePath)
&& Files.isExecutable(filePath);
}
代码示例来源:origin: apache/hive
@Override
public String validate(String value) {
final Path path = FileSystems.getDefault().getPath(value);
if (path == null && value != null) {
return String.format("Path '%s' provided could not be located.", value);
}
final boolean isDir = Files.isDirectory(path);
final boolean isWritable = Files.isWritable(path);
if (!isDir) {
return String.format("Path '%s' provided is not a directory.", value);
}
if (!isWritable) {
return String.format("Path '%s' provided is not writable.", value);
}
return null;
}
代码示例来源:origin: neo4j/neo4j
public static void checkWritableDirectory( Path directory ) throws FileSystemException
{
if ( !exists( directory ) )
{
throw new NoSuchFileException( directory.toString() );
}
if ( isRegularFile( directory ) )
{
throw new FileSystemException( directory.toString() + ": Not a directory" );
}
if ( !isWritable( directory ) )
{
throw new AccessDeniedException( directory.toString() );
}
}
代码示例来源:origin: bwssytems/ha-bridge
private void repositoryWriter(String content, Path filePath) {
if(Files.exists(filePath) && !Files.isWritable(filePath)){
log.error("Error file is not writable: " + filePath);
return;
}
if(Files.notExists(filePath.getParent())) {
try {
Files.createDirectories(filePath.getParent());
} catch (IOException e) {
log.error("Error creating the directory: " + filePath + " message: " + e.getMessage(), e);
}
}
try {
Path target = null;
if(Files.exists(filePath)) {
target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "device.db.old");
Files.move(filePath, target);
}
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
if(target != null)
Files.delete(target);
} catch (IOException e) {
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
}
}
代码示例来源:origin: bwssytems/ha-bridge
private void repositoryWriter(String content, Path filePath) {
if(Files.exists(filePath) && !Files.isWritable(filePath)){
log.error("Error file is not writable: " + filePath);
return;
}
if(Files.notExists(filePath.getParent())) {
try {
Files.createDirectories(filePath.getParent());
} catch (IOException e) {
log.error("Error creating the directory: " + filePath + " message: " + e.getMessage(), e);
}
}
try {
Path target = null;
if(Files.exists(filePath)) {
target = FileSystems.getDefault().getPath(filePath.getParent().toString(), "group.db.old");
Files.move(filePath, target);
}
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE);
if(target != null)
Files.delete(target);
} catch (IOException e) {
log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e);
}
}
代码示例来源:origin: apache/nifi
private Set<File> performListing(final File directory, final FileFilter filter, final boolean recurseSubdirectories) {
Path p = directory.toPath();
if (!Files.isWritable(p) || !Files.isReadable(p)) {
throw new IllegalStateException("Directory '" + directory + "' does not have sufficient permissions (i.e., not writable and readable)");
}
final Set<File> queue = new HashSet<>();
if (!directory.exists()) {
return queue;
}
final File[] children = directory.listFiles();
if (children == null) {
return queue;
}
for (final File child : children) {
if (child.isDirectory()) {
if (recurseSubdirectories) {
queue.addAll(performListing(child, filter, recurseSubdirectories));
}
} else if (filter.accept(child)) {
queue.add(child);
}
}
return queue;
}
代码示例来源:origin: apache/nifi
@Override
public void purge() {
// delete all content from repositories
for (final Path path : containers.values()) {
FileUtils.deleteFilesInDir(path.toFile(), null, LOG, true);
}
for (final Path path : containers.values()) {
if (!Files.exists(path)) {
throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " does not exist");
}
// Try up to 10 times to see if the directory is writable, in case another process (like a
// virus scanner) has the directory temporarily locked
boolean writable = false;
for (int i = 0; i < 10; i++) {
if (Files.isWritable(path)) {
writable = true;
break;
} else {
try {
Thread.sleep(100L);
} catch (final Exception e) {
}
}
}
if (!writable) {
throw new RepositoryPurgeException("File " + path.toFile().getAbsolutePath() + " is not writable");
}
}
resourceClaimManager.purge();
}
代码示例来源:origin: Graylog2/graylog2-server
checkState(tmpDir != null, "The temporary directory must not be null!");
final Path tmpPath = Paths.get(tmpDir);
if (!Files.isDirectory(tmpPath) || !Files.isWritable(tmpPath)) {
throw new IllegalStateException("Couldn't write to temporary directory: " + tmpPath.toAbsolutePath());
代码示例来源:origin: neo4j/neo4j
if ( Files.exists( lockFile ) )
if ( Files.isWritable( lockFile ) )
内容来源于网络,如有侵权,请联系作者删除!