org.gridlab.gat.io.attributes
Interface PosixFileAttributeView

All Superinterfaces:
AttributeView, BasicFileAttributeView, FileAttributeView, FileOwnerAttributeView

public interface PosixFileAttributeView
extends BasicFileAttributeView, FileOwnerAttributeView

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 owner, group-owner, and related access permissions. This file attribute view provides read and write access to these attributes.

The readAttributes method is used to read the file's attributes. The file owner is represented by a UserPrincipal that is the identity of the file owner for the purposes of access control. The 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 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 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:

     FileRef file = ...
     PosixFileAttributes attrs = file.newFileAttributeView(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 BasicFileAttributeView and FileOwnerAttributeView, and in addition, the following attributes are supported:

Name Type
"permissions" Set<PosixFilePermission>
"group" GroupPrincipal

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

The 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, setOwner, and setGroup methods respectively.

Since:
1.7

Method Summary
 String name()
          Returns the name of the attribute view.
 PosixFileAttributes readAttributes()
          Reads the basic file attributes as a bulk operation.
 void setGroup(GroupPrincipal group)
          Updates the file group-owner.
 void setPermissions(Set<PosixFilePermission> perms)
          Updates the file permissions.
 
Methods inherited from interface org.gridlab.gat.io.attributes.BasicFileAttributeView
setTimes
 
Methods inherited from interface org.gridlab.gat.io.attributes.FileOwnerAttributeView
getOwner, setOwner
 
Methods inherited from interface org.gridlab.gat.io.attributes.AttributeView
getAttribute, readAttributes, setAttribute
 

Method Detail

name

String name()
Returns the name of the attribute view. Attribute views of this type have the name "posix".

Specified by:
name in interface AttributeView
Specified by:
name in interface BasicFileAttributeView
Specified by:
name in interface FileOwnerAttributeView

readAttributes

PosixFileAttributes readAttributes()
                                   throws IOException
Description copied from interface: BasicFileAttributeView
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.

Specified by:
readAttributes in interface BasicFileAttributeView
Returns:
the file attributes
Throws:
IOException - if an I/O error occurs
SecurityException - In the case of the default provider, a security manager is installed, and it denies RuntimePermission("accessUserInformation") or its checkRead method denies read access to the file.

setPermissions

void setPermissions(Set<PosixFilePermission> perms)
                    throws IOException
Updates the file permissions.

Parameters:
perms - the new set of permissions
Throws:
ClassCastException - if the sets contains elements that are not of type PosixFilePermission
IOException - if an I/O error occurs
SecurityException - In the case of the default provider, a security manager is installed, and it denies RuntimePermission("accessUserInformation") or its checkWrite method denies write access to the file.

setGroup

void setGroup(GroupPrincipal group)
              throws IOException
Updates the file group-owner.

Parameters:
group - the new file group-owner
Throws:
IOException - if an I/O error occurs
SecurityException - In the case of the default provider, and a security manager is installed, it denies RuntimePermission("accessUserInformation") or its checkWrite method denies write access to the file.