java.nio.file.attribute.PosixFilePermission

Here are the examples of the java api class java.nio.file.attribute.PosixFilePermission taken from open source projects.

1. PosixFilePermissions#asFileAttribute()

Project: openjdk
File: PosixFilePermissions.java
/**
     * Creates a {@link FileAttribute}, encapsulating a copy of the given file
     * permissions, suitable for passing to the {@link java.nio.file.Files#createFile
     * createFile} or {@link java.nio.file.Files#createDirectory createDirectory}
     * methods.
     *
     * @param   perms
     *          the set of permissions
     *
     * @return  an attribute encapsulating the given file permissions with
     *          {@link FileAttribute#name name} {@code "posix:permissions"}
     *
     * @throws  ClassCastException
     *          if the set contains elements that are not of type {@code
     *          PosixFilePermission}
     */
public static FileAttribute<Set<PosixFilePermission>> asFileAttribute(Set<PosixFilePermission> perms) {
    // copy set and check for nulls (CCE will be thrown if an element is not
    // a PosixFilePermission)
    perms = new HashSet<>(perms);
    for (PosixFilePermission p : perms) {
        if (p == null)
            throw new NullPointerException();
    }
    final Set<PosixFilePermission> value = perms;
    return new FileAttribute<>() {

        @Override
        public String name() {
            return "posix:permissions";
        }

        @Override
        public Set<PosixFilePermission> value() {
            return Collections.unmodifiableSet(value);
        }
    };
}

2. IoUtils#validateExcludedPermissions()

Project: mina-sshd
File: IoUtils.java
/**
     * @param perms    The current {@link PosixFilePermission}s - ignored if {@code null}/empty
     * @param excluded The permissions <U>not</U> allowed to exist - ignored if {@code null}/empty
     * @return The violating {@link PosixFilePermission} - {@code null}
     * if no violating permission found
     */
public static PosixFilePermission validateExcludedPermissions(Collection<PosixFilePermission> perms, Collection<PosixFilePermission> excluded) {
    if (GenericUtils.isEmpty(perms) || GenericUtils.isEmpty(excluded)) {
        return null;
    }
    for (PosixFilePermission p : excluded) {
        if (perms.contains(p)) {
            return p;
        }
    }
    return null;
}

3. PosixFilePermissions#asFileAttribute()

Project: jdk7u-jdk
File: PosixFilePermissions.java
/**
     * Creates a {@link FileAttribute}, encapsulating a copy of the given file
     * permissions, suitable for passing to the {@link java.nio.file.Files#createFile
     * createFile} or {@link java.nio.file.Files#createDirectory createDirectory}
     * methods.
     *
     * @param   perms
     *          the set of permissions
     *
     * @return  an attribute encapsulating the given file permissions with
     *          {@link FileAttribute#name name} {@code "posix:permissions"}
     *
     * @throws  ClassCastException
     *          if the set contains elements that are not of type {@code
     *          PosixFilePermission}
     */
public static FileAttribute<Set<PosixFilePermission>> asFileAttribute(Set<PosixFilePermission> perms) {
    // copy set and check for nulls (CCE will be thrown if an element is not
    // a PosixFilePermission)
    perms = new HashSet<PosixFilePermission>(perms);
    for (PosixFilePermission p : perms) {
        if (p == null)
            throw new NullPointerException();
    }
    final Set<PosixFilePermission> value = perms;
    return new FileAttribute<Set<PosixFilePermission>>() {

        @Override
        public String name() {
            return "posix:permissions";
        }

        @Override
        public Set<PosixFilePermission> value() {
            return Collections.unmodifiableSet(value);
        }
    };
}

4. DefaultAuthorizedKeysAuthenticator#validateFilePath()

Project: mina-sshd
File: DefaultAuthorizedKeysAuthenticator.java
/**
     * @param path     The {@link Path} to be validated
     * @param perms    The current {@link PosixFilePermission}s
     * @param excluded The permissions <U>not</U> allowed to exist
     * @return The original path
     * @throws IOException If an excluded permission appears in the current ones
     */
protected Path validateFilePath(Path path, Collection<PosixFilePermission> perms, Collection<PosixFilePermission> excluded) throws IOException {
    PosixFilePermission p = IoUtils.validateExcludedPermissions(perms, excluded);
    if (p != null) {
        String filePath = path.toString();
        throw new FileSystemException(filePath, filePath, "File not allowed to have " + p + " permission: " + filePath);
    }
    return path;
}

5. ScpHelper#getOctalPermissions()

Project: mina-sshd
File: ScpHelper.java
public static String getOctalPermissions(Collection<PosixFilePermission> perms) {
    int pf = 0;
    for (PosixFilePermission p : perms) {
        switch(p) {
            case OWNER_READ:
                pf |= S_IRUSR;
                break;
            case OWNER_WRITE:
                pf |= S_IWUSR;
                break;
            case OWNER_EXECUTE:
                pf |= S_IXUSR;
                break;
            case GROUP_READ:
                pf |= S_IRGRP;
                break;
            case GROUP_WRITE:
                pf |= S_IWGRP;
                break;
            case GROUP_EXECUTE:
                pf |= S_IXGRP;
                break;
            case OTHERS_READ:
                pf |= S_IROTH;
                break;
            case OTHERS_WRITE:
                pf |= S_IWOTH;
                break;
            case OTHERS_EXECUTE:
                pf |= S_IXOTH;
                break;
            // ignored
            default:
        }
    }
    return String.format("%04o", pf);
}

6. SftpFileSystemProvider#getOctalPermissions()

Project: mina-sshd
File: SftpFileSystemProvider.java
public static String getOctalPermissions(Collection<PosixFilePermission> perms) {
    int pf = 0;
    for (PosixFilePermission p : perms) {
        switch(p) {
            case OWNER_READ:
                pf |= SftpConstants.S_IRUSR;
                break;
            case OWNER_WRITE:
                pf |= SftpConstants.S_IWUSR;
                break;
            case OWNER_EXECUTE:
                pf |= SftpConstants.S_IXUSR;
                break;
            case GROUP_READ:
                pf |= SftpConstants.S_IRGRP;
                break;
            case GROUP_WRITE:
                pf |= SftpConstants.S_IWGRP;
                break;
            case GROUP_EXECUTE:
                pf |= SftpConstants.S_IXGRP;
                break;
            case OTHERS_READ:
                pf |= SftpConstants.S_IROTH;
                break;
            case OTHERS_WRITE:
                pf |= SftpConstants.S_IWOTH;
                break;
            case OTHERS_EXECUTE:
                pf |= SftpConstants.S_IXOTH;
                break;
            // ignored
            default:
        }
    }
    return String.format("%04o", pf);
}

7. SftpFileSystemProvider#attributesToPermissions()

Project: mina-sshd
File: SftpFileSystemProvider.java
protected int attributesToPermissions(Path path, Collection<PosixFilePermission> perms) {
    if (GenericUtils.isEmpty(perms)) {
        return 0;
    }
    int pf = 0;
    for (PosixFilePermission p : perms) {
        switch(p) {
            case OWNER_READ:
                pf |= SftpConstants.S_IRUSR;
                break;
            case OWNER_WRITE:
                pf |= SftpConstants.S_IWUSR;
                break;
            case OWNER_EXECUTE:
                pf |= SftpConstants.S_IXUSR;
                break;
            case GROUP_READ:
                pf |= SftpConstants.S_IRGRP;
                break;
            case GROUP_WRITE:
                pf |= SftpConstants.S_IWGRP;
                break;
            case GROUP_EXECUTE:
                pf |= SftpConstants.S_IXGRP;
                break;
            case OTHERS_READ:
                pf |= SftpConstants.S_IROTH;
                break;
            case OTHERS_WRITE:
                pf |= SftpConstants.S_IWOTH;
                break;
            case OTHERS_EXECUTE:
                pf |= SftpConstants.S_IXOTH;
                break;
            default:
                if (log.isTraceEnabled()) {
                    log.trace("attributesToPermissions(" + path + ") ignored " + p);
                }
        }
    }
    return pf;
}

8. UnixAttributeProvider#toMode()

Project: jimfs
File: UnixAttributeProvider.java
@SuppressWarnings("OctalInteger")
private static int toMode(Set<PosixFilePermission> permissions) {
    int result = 0;
    for (PosixFilePermission permission : permissions) {
        checkNotNull(permission);
        switch(permission) {
            case OWNER_READ:
                // note: octal numbers
                result |= 0400;
                break;
            case OWNER_WRITE:
                result |= 0200;
                break;
            case OWNER_EXECUTE:
                result |= 0100;
                break;
            case GROUP_READ:
                result |= 0040;
                break;
            case GROUP_WRITE:
                result |= 0020;
                break;
            case GROUP_EXECUTE:
                result |= 0010;
                break;
            case OTHERS_READ:
                result |= 0004;
                break;
            case OTHERS_WRITE:
                result |= 0002;
                break;
            case OTHERS_EXECUTE:
                result |= 0001;
                break;
            default:
                // no other possible values
                throw new AssertionError();
        }
    }
    return result;
}

9. OsUtils#posixFilePermissions()

Project: eclipse-integration-commons
File: OsUtils.java
public static Set<PosixFilePermission> posixFilePermissions(int mode) {
    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;
}

10. LocalFilesystemConnector#fromPermissions()

Project: cloudsync
File: LocalFilesystemConnector.java
private Integer fromPermissions(final Set<PosixFilePermission> posixPerms) {
    int result = 0;
    for (final PosixFilePermission posixPerm : posixPerms) {
        result += fromPermMapping.get(posixPerm);
    }
    return result;
}