Here you can find the source of getPosixPermissions(int fileMode)
Parameter | Description |
---|---|
fileMode | Integer representing a file mode |
public static Set<PosixFilePermission> getPosixPermissions(int fileMode)
//package com.java2s; /*/*w ww . j a v a 2 s . c om*/ * Copyright 2018 Google, Inc. * * 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 * * 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. */ import java.nio.file.attribute.PosixFilePermission; import java.util.HashSet; import java.util.Set; public class Main { private static PosixFilePermission[] permissionBits = new PosixFilePermission[] { 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 }; /** * Given an integer representing file permissions, returns a set of PosixFilePermissions * representing the corresponding permissions. * @param fileMode Integer representing a file mode * @return Set of permissions in the input mode */ public static Set<PosixFilePermission> getPosixPermissions(int fileMode) { Set<PosixFilePermission> posixPermissions = new HashSet<>(); for (int i = 0; i < permissionBits.length; i++) { int bit = fileMode & (1 << i); if (bit != 0) { posixPermissions.add(permissionBits[i]); } } return posixPermissions; } }