List of utility methods to do Posix
void | addPermissions(Set add Permissions if ((mode & 1) == 1) { permissions.add(PosixFilePermission.valueOf(prefix + "_EXECUTE")); if ((mode & 2) == 2) { permissions.add(PosixFilePermission.valueOf(prefix + "_WRITE")); if ((mode & 4) == 4) { permissions.add(PosixFilePermission.valueOf(prefix + "_READ")); ... |
String | fromPosixPermission(PosixFilePermission permission) from Posix Permission switch (permission) { case OWNER_READ: case GROUP_READ: case OTHERS_READ: return READ; case OWNER_WRITE: case GROUP_WRITE: case OTHERS_WRITE: ... |
int | getFileMode(Set Given a set of PosixFilePermissions, returns an integer with the corresponding permission bits set int fileMode = 0; for (int i = 0; i < permissionBits.length; i++) { if (posixPermissions.contains(permissionBits[i])) { fileMode += 1 << i; return fileMode; |
PosixFileAttributes | getPosixFileAttributes(@Nonnull File file) get Posix File Attributes return Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); |
Set | getPosixFilePermissions(int mode) Convert integer mode to PosixFilePermission object. Set<PosixFilePermission> result = EnumSet.noneOf(PosixFilePermission.class); if ((mode & 0400) != 0) { result.add(PosixFilePermission.OWNER_READ); if ((mode & 0200) != 0) { result.add(PosixFilePermission.OWNER_WRITE); if ((mode & 0100) != 0) { ... |
Set | getPosixPermissions(File forFile) get Posix Permissions if (IS_POSIX) { try { return Files.getPosixFilePermissions(Paths.get(forFile.toURI())); } catch (IOException e) { throw new RuntimeException(e); return new TreeSet<PosixFilePermission>(); ... |
Set | getPosixPermissions(int fileMode) Given an integer representing file permissions, returns a set of PosixFilePermissions representing the corresponding permissions. Set<PosixFilePermission> posixPermissions = new HashSet<>(); for (int i = 0; i < permissionBits.length; i++) { int bit = fileMode & (1 << i); if (bit != 0) { posixPermissions.add(permissionBits[i]); return posixPermissions; ... |
int | getPosixPermissionsAsInt(Set get Posix Permissions As Int int result = 0; if (permissionSet.contains(PosixFilePermission.OWNER_READ)) { result = result | O400; if (permissionSet.contains(PosixFilePermission.OWNER_WRITE)) { result = result | O200; if (permissionSet.contains(PosixFilePermission.OWNER_EXECUTE)) { ... |
boolean | givePerm(File f, Set Sets specified permissions to a single file or directory. try { Path p = Paths.get(f.toURI()); if (OS.indexOf("win") >= 0) { p.toFile().setWritable(true); } else { Files.setPosixFilePermissions(p, perms); } catch (IOException e) { ... |
boolean | givePerms(File f, Set Sets permissions to file or directory given. boolean success = givePerm(f, perms); if (f.isDirectory() && recursive) { File[] files = f.listFiles(); for (File file : files) { if (!givePerms(file, perms, recursive)) { success = false; return success; |