Java Posix getPosixPermissionsAsInt( Set permissionSet)

Here you can find the source of getPosixPermissionsAsInt( Set permissionSet)

Description

get Posix Permissions As Int

License

Open Source License

Declaration

public static int getPosixPermissionsAsInt(
            Set<PosixFilePermission> permissionSet) 

Method Source Code

//package com.java2s;

import java.nio.file.attribute.PosixFilePermission;

import java.util.Set;

public class Main {
    private static final int O400 = 256;
    private static final int O200 = 128;
    private static final int O100 = 64;
    private static final int O040 = 32;
    private static final int O020 = 16;
    private static final int O010 = 8;
    private static final int O004 = 4;
    private static final int O002 = 2;
    private static final int O001 = 1;

    public static int getPosixPermissionsAsInt(
            Set<PosixFilePermission> permissionSet) {
        int result = 0;
        if (permissionSet.contains(PosixFilePermission.OWNER_READ)) {
            result = result | O400;//  w w w  . j a  v a 2 s. c  o  m
        }
        if (permissionSet.contains(PosixFilePermission.OWNER_WRITE)) {
            result = result | O200;
        }
        if (permissionSet.contains(PosixFilePermission.OWNER_EXECUTE)) {
            result = result | O100;
        }
        if (permissionSet.contains(PosixFilePermission.GROUP_READ)) {
            result = result | O040;
        }
        if (permissionSet.contains(PosixFilePermission.GROUP_WRITE)) {
            result = result | O020;
        }
        if (permissionSet.contains(PosixFilePermission.GROUP_EXECUTE)) {
            result = result | O010;
        }
        if (permissionSet.contains(PosixFilePermission.OTHERS_READ)) {
            result = result | O004;
        }
        if (permissionSet.contains(PosixFilePermission.OTHERS_WRITE)) {
            result = result | O002;
        }
        if (permissionSet.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            result = result | O001;
        }
        return result;
    }
}

Related

  1. getFileMode(Set posixPermissions)
  2. getPosixFileAttributes(@Nonnull File file)
  3. getPosixFilePermissions(int mode)
  4. getPosixPermissions(File forFile)
  5. getPosixPermissions(int fileMode)
  6. givePerm(File f, Set perms)
  7. givePerms(File f, Set perms, boolean recursive)
  8. intFilePermissions(Set permissions)
  9. mapValue(PosixFilePermission p)