Java Posix intFilePermissions(Set permissions)

Here you can find the source of intFilePermissions(Set permissions)

Description

int File Permissions

License

Open Source License

Declaration

public static int intFilePermissions(Set<PosixFilePermission> permissions) 

Method Source Code

//package com.java2s;
/*/*from  ww  w. ja v  a2 s.com*/
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 3 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 3 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;

public class Main {
    public static int intFilePermissions(Set<PosixFilePermission> permissions) {
        int r = 0;
        for (PosixFilePermission pfp : permissions) {
            // @formatter:off
            switch (pfp) {
            case OTHERS_EXECUTE:
                r |= 1;
                break;
            case OTHERS_WRITE:
                r |= 2;
                break;
            case OTHERS_READ:
                r |= 4;
                break;
            case GROUP_EXECUTE:
                r |= 8;
                break;
            case GROUP_WRITE:
                r |= 16;
                break;
            case GROUP_READ:
                r |= 32;
                break;
            case OWNER_EXECUTE:
                r |= 64;
                break;
            case OWNER_WRITE:
                r |= 128;
                break;
            case OWNER_READ:
                r |= 256;
                break;
            }
            // @formatter:on
        }
        return r;
    }
}

Related

  1. getPosixPermissions(File forFile)
  2. getPosixPermissions(int fileMode)
  3. getPosixPermissionsAsInt( Set permissionSet)
  4. givePerm(File f, Set perms)
  5. givePerms(File f, Set perms, boolean recursive)
  6. mapValue(PosixFilePermission p)
  7. posixFilePermissions(int mode)
  8. setPermissionsToFile(File f, Collection perms)
  9. toOctalFileMode(Set permissions)