Java Posix unixModeToPosixSet(int unixMode)

Here you can find the source of unixModeToPosixSet(int unixMode)

Description

unix Mode To Posix Set

License

Apache License

Declaration

public static Set<PosixFilePermission> unixModeToPosixSet(int unixMode) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.file.attribute.PosixFilePermission;

import java.util.Set;
import java.util.TreeSet;

public class Main {
    public static PosixFilePermission[] posixFilePermissionsBitSorted = { PosixFilePermission.OTHERS_EXECUTE,
            PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_EXECUTE,
            PosixFilePermission.GROUP_WRITE, PosixFilePermission.GROUP_READ, PosixFilePermission.OWNER_EXECUTE,
            PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ };

    public static Set<PosixFilePermission> unixModeToPosixSet(int unixMode) {
        Set<PosixFilePermission> permissions = new TreeSet<PosixFilePermission>();
        int bit = 8;
        //StringBuilder sb = new StringBuilder();
        while (bit >= 0) {
            if ((unixMode & (1 << bit)) != 0) {
                permissions.add(posixFilePermissionsBitSorted[bit]);
                //sb.append("1");
            } else {
                //sb.append("0");
            }/*from w w  w .  j  av a 2s  .c  o m*/
            --bit;
        }
        //System.out.println(sb.toString());
        return permissions;
    }
}

Related

  1. mapValue(PosixFilePermission p)
  2. posixFilePermissions(int mode)
  3. setPermissionsToFile(File f, Collection perms)
  4. toOctalFileMode(Set permissions)
  5. toUnixFileMode(Set perms)