3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 893N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 893N/A * A file attribute view that provides a view of the file attributes commonly 893N/A * associated with files on file systems used by operating systems that implement 893N/A * the Portable Operating System Interface (POSIX) family of standards. 893N/A * POSIX</a> family of standards commonly use file systems that have a 893N/A * file <em>owner</em>, <em>group-owner</em>, and related <em>access 893N/A * permissions</em>. This file attribute view provides read and write access 893N/A * <p> The {@link #readAttributes() readAttributes} method is used to read the 893N/A * file's attributes. The file {@link PosixFileAttributes#owner() owner} is 893N/A * represented by a {@link UserPrincipal} that is the identity of the file owner 893N/A * for the purposes of access control. The {@link PosixFileAttributes#group() 893N/A * group-owner}, represented by a {@link GroupPrincipal}, is the identity of the 893N/A * group owner, where a group is an identity created for administrative purposes 893N/A * so as to determine the access rights for the members of the group. 893N/A * <p> The {@link PosixFileAttributes#permissions() permissions} attribute is a 893N/A * set of access permissions. This file attribute view provides access to the nine 893N/A * permission defined by the {@link PosixFilePermission} class. 893N/A * These nine permission bits determine the <em>read</em>, <em>write</em>, and 893N/A * <em>execute</em> access for the file owner, group, and others (others 893N/A * meaning identities other than the owner and members of the group). Some 893N/A * operating systems and file systems may provide additional permission bits 893N/A * but access to these other bits is not defined by this class in this release. 893N/A * <p> <b>Usage Example:</b> 893N/A * Suppose we need to print out the owner and access permissions of a file: 3471N/A * PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class) 893N/A * System.out.format("%s %s%n", 893N/A * attrs.owner().getName(), 893N/A * PosixFilePermissions.toString(attrs.permissions())); 893N/A * <h4> Dynamic Access </h4> 893N/A * <p> Where dynamic access to file attributes is required, the attributes 893N/A * supported by this attribute view are as defined by {@link 893N/A * BasicFileAttributeView} and {@link FileOwnerAttributeView}, and in addition, 893N/A * the following attributes are supported: 893N/A * <table border="1" cellpadding="8"> 893N/A * <td> "permissions" </td> 893N/A * <td> {@link Set}<{@link PosixFilePermission}> </td> 893N/A * <td> {@link GroupPrincipal} </td> 3471N/A * <p> The {@link Files#getAttribute getAttribute} method may be used to read 1319N/A * any of these attributes, or any of the attributes defined by {@link 1319N/A * BasicFileAttributeView} as if by invoking the {@link #readAttributes 893N/A * readAttributes()} method. 3471N/A * <p> The {@link Files#setAttribute setAttribute} method may be used to update 1319N/A * the file's last modified time, last access time or create time attributes as 893N/A * defined by {@link BasicFileAttributeView}. It may also be used to update 893N/A * the permissions, owner, or group-owner as if by invoking the {@link 893N/A * #setPermissions setPermissions}, {@link #setOwner setOwner}, and {@link 893N/A * #setGroup setGroup} methods respectively. 893N/A * <h4> Setting Initial Permissions </h4> 893N/A * <p> Implementations supporting this attribute view may also support setting 893N/A * the initial permissions when creating a file or directory. The 3471N/A * initial permissions are provided to the {@link Files#createFile createFile} 3471N/A * or {@link Files#createDirectory createDirectory} methods as a {@link 893N/A * FileAttribute} with {@link FileAttribute#name name} {@code "posix:permissions"} 893N/A * and a {@link FileAttribute#value value} that is the set of permissions. The 893N/A * following example uses the {@link PosixFilePermissions#asFileAttribute 893N/A * asFileAttribute} method to construct a {@code FileAttribute} when creating a 893N/A * Set<PosixFilePermission> perms = 893N/A * EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ); 3471N/A * Files.createFile(path, PosixFilePermissions.asFileAttribute(perms)); 893N/A * <p> When the access permissions are set at file creation time then the actual 893N/A * value of the permissions may differ that the value of the attribute object. 893N/A * The reasons for this are implementation specific. On UNIX systems, for 893N/A * example, a process has a <em>umask</em> that impacts the permission bits 893N/A * of newly created files. Where an implementation supports the setting of 893N/A * the access permissions, and the underlying file system supports access 893N/A * permissions, then it is required that the value of the actual access 893N/A * permissions will be equal or less than the value of the attribute 3471N/A * provided to the {@link Files#createFile createFile} or {@link 3471N/A * Files#createDirectory createDirectory} methods. In other words, the file may 3471N/A * be more secure than requested. 893N/A * Returns the name of the attribute view. Attribute views of this type 893N/A * have the name {@code "posix"}. 893N/A * @throws IOException {@inheritDoc} 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> 893N/A * or its {@link SecurityManager#checkRead(String) checkRead} method 893N/A * denies read access to the file. 893N/A * Updates the file permissions. 908N/A * the new set of permissions 893N/A * @throws ClassCastException 908N/A * if the sets contains elements that are not of type {@code 908N/A * if an I/O error occurs 893N/A * @throws SecurityException 893N/A * In the case of the default provider, a security manager is 893N/A * installed, and it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> 893N/A * or its {@link SecurityManager#checkWrite(String) checkWrite} 893N/A * method denies write access to the file. 893N/A * Updates the file group-owner. 908N/A * the new file group-owner 908N/A * if an I/O error occurs 893N/A * @throws SecurityException 893N/A * In the case of the default provider, and a security manager is 893N/A * installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt> 893N/A * or its {@link SecurityManager#checkWrite(String) checkWrite} 893N/A * method denies write access to the file.