# PosixFileAttributeView

public interface **PosixFileAttributeView** implements [BasicFileAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html) [FileOwnerAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html) A file attribute view that provides a view of the file attributes commonly
associated with files on file systems used by operating systems that implement
the Portable Operating System Interface (POSIX) family of standards.

Operating systems that implement the [POSIX](http://www.opengroup.org) family of standards commonly use file systems that have a
file *owner* , *group-owner* , and related *access
permissions*. This file attribute view provides read and write access
to these attributes.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#readAttributes()` method is used to read the
file's attributes. The file `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html#owner()` is
represented by a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html` that is the identity of the file owner
for the purposes of access control. The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html#group()`, represented by a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/GroupPrincipal.html`, is the identity of the
group owner, where a group is an identity created for administrative purposes
so as to determine the access rights for the members of the group.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html#permissions()` attribute is a
set of access permissions. This file attribute view provides access to the nine
permission defined by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFilePermission.html` class.
These nine permission bits determine the *read* , *write* , and
*execute* access for the file owner, group, and others (others
meaning identities other than the owner and members of the group). Some
operating systems and file systems may provide additional permission bits
but access to these other bits is not defined by this class in this release.

**Usage Example:**
Suppose we need to print out the owner and access permissions of a file:

```
     Path file = ...
     PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class)
         .readAttributes();
     System.out.format("%s %s%n",
         attrs.owner().getName(),
         PosixFilePermissions.toString(attrs.permissions()));
 
```

## Dynamic Access

Where dynamic access to file attributes is required, the attributes
supported by this attribute view are as defined by `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html`, and in addition,
the following attributes are supported:
>
> | Name | Type |
> |---|---|
> | "permissions" | `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html`\<`https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFilePermission.html`\> |
> | "group" | `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/GroupPrincipal.html` |

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#getAttribute(java.nio.file.Path,%20java.lang.String,%20java.nio.file.LinkOption...)` method may be used to read
any of these attributes, or any of the attributes defined by `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html` as if by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#readAttributes()` method.

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#setAttribute(java.nio.file.Path,%20java.lang.String,%20java.lang.Object,%20java.nio.file.LinkOption...)` method may be used to update
the file's last modified time, last access time or create time attributes as
defined by `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html`. It may also be used to update
the permissions, owner, or group-owner as if by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#setPermissions(java.util.Set<java.nio.file.attribute.PosixFilePermission>)`, `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#setOwner(java.nio.file.attribute.UserPrincipal)`, and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#setGroup(java.nio.file.attribute.GroupPrincipal)` methods respectively.

## Setting Initial Permissions

Implementations supporting this attribute view may also support setting
the initial permissions when creating a file or directory. The
initial permissions are provided to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createFile(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)`
or `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createDirectory(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)` methods as a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html` with `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html#name()` `"posix:permissions"`
and a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileAttribute.html#value()` that is the set of permissions. The
following example uses the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFilePermissions.html#asFileAttribute(java.util.Set<java.nio.file.attribute.PosixFilePermission>)` method to construct a `FileAttribute` when creating a
file:

```
     Path path = ...
     Set<PosixFilePermission> perms =
         EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ);
     Files.createFile(path, PosixFilePermissions.asFileAttribute(perms));
 
```

When the access permissions are set at file creation time then the actual
value of the permissions may differ that the value of the attribute object.
The reasons for this are implementation specific. On UNIX systems, for
example, a process has a *umask* that impacts the permission bits
of newly created files. Where an implementation supports the setting of
the access permissions, and the underlying file system supports access
permissions, then it is required that the value of the actual access
permissions will be equal or less than the value of the attribute
provided to the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createFile(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)` or `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/Files.html#createDirectory(java.nio.file.Path,%20java.nio.file.attribute.FileAttribute<?>...)` methods. In other words, the file may
be more secure than requested.

### Public Method Summary

|---|---|
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#name())() Returns the name of the attribute view. |
| abstract [PosixFileAttributes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html) | [readAttributes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#readAttributes())() Reads the basic file attributes as a bulk operation. |
| abstract void | [setGroup](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#setGroup(java.nio.file.attribute.GroupPrincipal))([GroupPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/GroupPrincipal.html) group) Updates the file group-owner. |
| abstract void | [setPermissions](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributeView.html#setPermissions(java.util.Set<java.nio.file.attribute.PosixFilePermission>))([Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[PosixFilePermission](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFilePermission.html)\> perms) Updates the file permissions. |

### Inherited Method Summary

From interface [java.nio.file.attribute.BasicFileAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html)

|---|---|
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html#name())() Returns the name of the attribute view. |
| abstract [BasicFileAttributes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributes.html) | [readAttributes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html#readAttributes())() Reads the basic file attributes as a bulk operation. |
| abstract void | [setTimes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/BasicFileAttributeView.html#setTimes(java.nio.file.attribute.FileTime,%20java.nio.file.attribute.FileTime,%20java.nio.file.attribute.FileTime))(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) Updates any or all of the file's last modified time, last access time, and create time attributes. |

From interface [java.nio.file.attribute.FileOwnerAttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html)

|---|---|
| abstract [UserPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html) | [getOwner](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#getOwner())() Read the file owner. |
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#name())() Returns the name of the attribute view. |
| abstract void | [setOwner](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/FileOwnerAttributeView.html#setOwner(java.nio.file.attribute.UserPrincipal))([UserPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/UserPrincipal.html) owner) Updates the file owner. |

From interface [java.nio.file.attribute.AttributeView](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AttributeView.html)

|---|---|
| abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [name](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/AttributeView.html#name())() Returns the name of the attribute view. |

## Public Methods

#### public abstract [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**name**
()

Returns the name of the attribute view. Attribute views of this type
have the name `"posix"`.

##### Returns

- the name of the attribute view

#### public abstract [PosixFileAttributes](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFileAttributes.html)
**readAttributes**
()

Reads the basic file attributes as a bulk operation.

It is implementation specific if all file attributes are read as an
atomic operation with respect to other file system operations.

##### Returns

- the file attributes

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | In the case of the default provider, a security manager is installed, and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`("accessUserInformation") or its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkRead(java.lang.String)` method denies read access to the file. |
|---|---|

#### public abstract void
**setGroup**
([GroupPrincipal](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/GroupPrincipal.html) group)

Updates the file group-owner.

##### Parameters

| group | the new file group-owner |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | In the case of the default provider, and a security manager is installed, it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`("accessUserInformation") or its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkWrite(java.lang.String)` method denies write access to the file. |
|---|---|

#### public abstract void
**setPermissions**
([Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[PosixFilePermission](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/attribute/PosixFilePermission.html)\> perms)

Updates the file permissions.

##### Parameters

| perms | the new set of permissions |
|---|---|

##### Throws

| [ClassCastException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ClassCastException.html) | if the sets contains elements that are not of type `PosixFilePermission` |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | In the case of the default provider, a security manager is installed, and it denies `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimePermission.html`("accessUserInformation") or its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkWrite(java.lang.String)` method denies write access to the file. |
|---|---|