mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8246592: Simplify checking of boolean file attributes
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
1786701011
commit
9cd41b6555
4 changed files with 47 additions and 9 deletions
|
@ -820,7 +820,7 @@ public class File
|
|||
if (isInvalid()) {
|
||||
return false;
|
||||
}
|
||||
return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0);
|
||||
return fs.hasBooleanAttributes(this, FileSystem.BA_EXISTS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -850,8 +850,7 @@ public class File
|
|||
if (isInvalid()) {
|
||||
return false;
|
||||
}
|
||||
return ((fs.getBooleanAttributes(this) & FileSystem.BA_DIRECTORY)
|
||||
!= 0);
|
||||
return fs.hasBooleanAttributes(this, FileSystem.BA_DIRECTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -883,7 +882,7 @@ public class File
|
|||
if (isInvalid()) {
|
||||
return false;
|
||||
}
|
||||
return ((fs.getBooleanAttributes(this) & FileSystem.BA_REGULAR) != 0);
|
||||
return fs.hasBooleanAttributes(this, FileSystem.BA_REGULAR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -912,7 +911,7 @@ public class File
|
|||
if (isInvalid()) {
|
||||
return false;
|
||||
}
|
||||
return ((fs.getBooleanAttributes(this) & FileSystem.BA_HIDDEN) != 0);
|
||||
return fs.hasBooleanAttributes(this, FileSystem.BA_HIDDEN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2103,7 +2102,7 @@ public class File
|
|||
throw se;
|
||||
}
|
||||
}
|
||||
} while ((fs.getBooleanAttributes(f) & FileSystem.BA_EXISTS) != 0);
|
||||
} while (fs.hasBooleanAttributes(f, FileSystem.BA_EXISTS));
|
||||
|
||||
if (!fs.createFileExclusively(f.getPath()))
|
||||
throw new IOException("Unable to create temporary file");
|
||||
|
|
|
@ -111,6 +111,15 @@ abstract class FileSystem {
|
|||
*/
|
||||
public abstract int getBooleanAttributes(File f);
|
||||
|
||||
/**
|
||||
* Checks if all the given boolean attributes are true for the file or
|
||||
* directory denoted by the given abstract pathname. False if it does not
|
||||
* exist or some other I/O error occurs.
|
||||
*/
|
||||
public boolean hasBooleanAttributes(File f, int attributes) {
|
||||
return (getBooleanAttributes(f) & attributes) == attributes;
|
||||
}
|
||||
|
||||
@Native public static final int ACCESS_READ = 0x04;
|
||||
@Native public static final int ACCESS_WRITE = 0x02;
|
||||
@Native public static final int ACCESS_EXECUTE = 0x01;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue