Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/UnixFileModeAttribute.java
32288 views
/*1* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.nio.fs;2627import java.nio.file.attribute.*;28import java.util.*;2930class UnixFileModeAttribute {31static final int ALL_PERMISSIONS =32UnixConstants.S_IRUSR | UnixConstants.S_IWUSR | UnixConstants.S_IXUSR |33UnixConstants.S_IRGRP | UnixConstants.S_IWGRP | UnixConstants.S_IXGRP |34UnixConstants.S_IROTH | UnixConstants.S_IWOTH | UnixConstants. S_IXOTH;3536static final int ALL_READWRITE =37UnixConstants.S_IRUSR | UnixConstants.S_IWUSR |38UnixConstants.S_IRGRP | UnixConstants.S_IWGRP |39UnixConstants.S_IROTH | UnixConstants.S_IWOTH;4041static final int TEMPFILE_PERMISSIONS =42UnixConstants.S_IRUSR | UnixConstants.S_IWUSR | UnixConstants.S_IXUSR;4344private UnixFileModeAttribute() {45}4647static int toUnixMode(Set<PosixFilePermission> perms) {48int mode = 0;49for (PosixFilePermission perm: perms) {50if (perm == null)51throw new NullPointerException();52switch (perm) {53case OWNER_READ : mode |= UnixConstants.S_IRUSR; break;54case OWNER_WRITE : mode |= UnixConstants.S_IWUSR; break;55case OWNER_EXECUTE : mode |= UnixConstants.S_IXUSR; break;56case GROUP_READ : mode |= UnixConstants.S_IRGRP; break;57case GROUP_WRITE : mode |= UnixConstants.S_IWGRP; break;58case GROUP_EXECUTE : mode |= UnixConstants.S_IXGRP; break;59case OTHERS_READ : mode |= UnixConstants.S_IROTH; break;60case OTHERS_WRITE : mode |= UnixConstants.S_IWOTH; break;61case OTHERS_EXECUTE : mode |= UnixConstants.S_IXOTH; break;62}63}64return mode;65}6667@SuppressWarnings("unchecked")68static int toUnixMode(int defaultMode, FileAttribute<?>... attrs) {69int mode = defaultMode;70for (FileAttribute<?> attr: attrs) {71String name = attr.name();72if (!name.equals("posix:permissions") && !name.equals("unix:permissions")) {73throw new UnsupportedOperationException("'" + attr.name() +74"' not supported as initial attribute");75}76mode = toUnixMode((Set<PosixFilePermission>)attr.value());77}78return mode;79}80}818283