Java Posix toUnixFileMode(Set perms)

Here you can find the source of toUnixFileMode(Set perms)

Description

to Unix File Mode

License

Apache License

Declaration

public static int toUnixFileMode(Set<PosixFilePermission> perms) 

Method Source Code

//package com.java2s;
/*//w  w w. j  a v a  2s  . c  o  m
 * Copyright 2012-2014 Netherlands eScience Center.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at the following location:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * For the full license, see: LICENSE.txt (located in the root folder of this distribution).
 * ---
 */

import java.nio.file.attribute.PosixFilePermission;

import java.util.Set;

public class Main {
    public static int toUnixFileMode(Set<PosixFilePermission> perms) {
        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))
            mode |= 0040;
        if (perms.contains(PosixFilePermission.GROUP_WRITE))
            mode |= 0020;
        if (perms.contains(PosixFilePermission.GROUP_EXECUTE))
            mode |= 0010;
        if (perms.contains(PosixFilePermission.OTHERS_READ))
            mode |= 0004;
        if (perms.contains(PosixFilePermission.OTHERS_WRITE))
            mode |= 0002;
        if (perms.contains(PosixFilePermission.OTHERS_EXECUTE))
            mode |= 0001;

        return mode;
    }
}

Related

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