Compartilhar via


IPosixFileAttributeView Interface

Definition

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.

[Android.Runtime.Register("java/nio/file/attribute/PosixFileAttributeView", "", "Java.Nio.FileNio.Attributes.IPosixFileAttributeViewInvoker", ApiSince=26)]
public interface IPosixFileAttributeView : IDisposable, Java.Interop.IJavaPeerable, Java.Nio.FileNio.Attributes.IBasicFileAttributeView, Java.Nio.FileNio.Attributes.IFileOwnerAttributeView
[<Android.Runtime.Register("java/nio/file/attribute/PosixFileAttributeView", "", "Java.Nio.FileNio.Attributes.IPosixFileAttributeViewInvoker", ApiSince=26)>]
type IPosixFileAttributeView = interface
    interface IBasicFileAttributeView
    interface IFileAttributeView
    interface IAttributeView
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IFileOwnerAttributeView
Attributes
Implements

Remarks

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 family of standards commonly use file systems that have a file <em>owner</em>, <em>group-owner</em>, and related <em>access permissions</em>. This file attribute view provides read and write access to these attributes.

The #readAttributes() readAttributes method is used to read the file's attributes. The file PosixFileAttributes#owner() owner is represented by a UserPrincipal that is the identity of the file owner for the purposes of access control. The PosixFileAttributes#group() group-owner, represented by a GroupPrincipal, 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 PosixFileAttributes#permissions() permissions attribute is a set of access permissions. This file attribute view provides access to the nine permission defined by the PosixFilePermission class. These nine permission bits determine the <em>read</em>, <em>write</em>, and <em>execute</em> 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.

<b>Usage Example:</b> 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()));

<h2> Dynamic Access </h2>

Where dynamic access to file attributes is required, the attributes supported by this attribute view are as defined by BasicFileAttributeView and FileOwnerAttributeView, and in addition, the following attributes are supported: <blockquote> <table class="striped"> <caption style="display:none">Supported attributes</caption> <thead> <tr> <th scope="col"> Name </th> <th scope="col"> Type </th> </tr> </thead> <tbody> <tr> <th scope="row"> "permissions" </th> <td> Set&lt;PosixFilePermission&gt; </td> </tr> <tr> <th scope="row"> "group" </th> <td> GroupPrincipal</td> </tr> </tbody> </table> </blockquote>

The Files#getAttribute getAttribute method may be used to read any of these attributes, or any of the attributes defined by BasicFileAttributeView as if by invoking the #readAttributes readAttributes() method.

The Files#setAttribute setAttribute method may be used to update the file's last modified time, last access time or create time attributes as defined by BasicFileAttributeView. It may also be used to update the permissions, owner, or group-owner as if by invoking the #setPermissions setPermissions, #setOwner setOwner, and #setGroup setGroup methods respectively.

<h2> Setting Initial Permissions </h2>

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 Files#createFile createFile or Files#createDirectory createDirectory methods as a FileAttribute with FileAttribute#name name"posix:permissions" and a FileAttribute#value value that is the set of permissions. The following example uses the PosixFilePermissions#asFileAttribute asFileAttribute method to construct a FileAttribute when creating a file:

Path path = ...
                Set&lt;PosixFilePermission&gt; 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 <em>umask</em> 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 Files#createFile createFile or Files#createDirectory createDirectory methods. In other words, the file may be more secure than requested.

Added in 1.7.

Java documentation for java.nio.file.attribute.PosixFileAttributeView.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
Owner (Inherited from IFileOwnerAttributeView)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
Name()

Returns the name of the attribute view.

ReadAttributes()
SetGroup(IGroupPrincipal)

Updates the file group-owner.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
SetPermissions(ICollection<PosixFilePermission>)

Updates the file permissions.

SetTimes(FileTime, FileTime, FileTime)

Updates any or all of the file's last modified time, last access time, and create time attributes.

(Inherited from IBasicFileAttributeView)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to