Java Utililty Methods Posix

List of utility methods to do Posix

Description

The list of methods to do Posix are organized into topic(s).

Method

intintFilePermissions(Set permissions)
int File Permissions
int r = 0;
for (PosixFilePermission pfp : permissions) {
    switch (pfp) {
    case OTHERS_EXECUTE:
        r |= 1;
        break;
    case OTHERS_WRITE:
        r |= 2;
...
intmapValue(PosixFilePermission p)
map Value
switch (p) {
case GROUP_EXECUTE:
    return 1 * 8;
case GROUP_READ:
    return 4 * 8;
case GROUP_WRITE:
    return 2 * 8;
case OWNER_EXECUTE:
...
SetposixFilePermissions(int mode)
posix File Permissions
int mask = 1;
Set<PosixFilePermission> perms = EnumSet.noneOf(PosixFilePermission.class);
for (PosixFilePermission flag : decodeMap) {
    if (flag != null && (mask & mode) != 0) {
        perms.add(flag);
    mask = mask << 1;
return perms;
voidsetPermissionsToFile(File f, Collection perms)
set Permissions To File
boolean readable = perms != null
        && (perms.contains(PosixFilePermission.OWNER_READ) || perms.contains(PosixFilePermission.GROUP_READ)
                || perms.contains(PosixFilePermission.OTHERS_READ));
f.setReadable(readable, false);
boolean writable = perms != null && (perms.contains(PosixFilePermission.OWNER_WRITE)
        || perms.contains(PosixFilePermission.GROUP_WRITE)
        || perms.contains(PosixFilePermission.OTHERS_WRITE));
f.setWritable(writable, false);
...
inttoOctalFileMode(Set permissions)
Converts a set of PosixFilePermission to chmod-style octal file mode.
int result = 0;
for (PosixFilePermission permissionBit : permissions) {
    switch (permissionBit) {
    case OWNER_READ:
        result |= OWNER_READ_FILEMODE;
        break;
    case OWNER_WRITE:
        result |= OWNER_WRITE_FILEMODE;
...
inttoUnixFileMode(Set perms)
to Unix File Mode
int mode = 0;
if (perms.contains(PosixFilePermission.OWNER_READ))
    mode |= 0400;
if (perms.contains(PosixFilePermission.OWNER_WRITE))
    mode |= 0200;
if (perms.contains(PosixFilePermission.OWNER_EXECUTE))
    mode |= 0100;
if (perms.contains(PosixFilePermission.GROUP_READ))
...
SetunixModeToPosixSet(int unixMode)
unix Mode To Posix Set
Set<PosixFilePermission> permissions = new TreeSet<PosixFilePermission>();
int bit = 8;
while (bit >= 0) {
    if ((unixMode & (1 << bit)) != 0) {
        permissions.add(posixFilePermissionsBitSorted[bit]);
    } else {
    --bit;
...