Spec-Zone .ru
спецификации, руководства, описания, API
Please note that the specifications and other information contained herein are not final and are subject to change. The information is being made available to you solely for purpose of evaluation.

Java™ Platform
Standard Ed. 7

DRAFT ea-b118

java.nio.file.attribute
Class Attributes

java.lang.Object
  extended by java.nio.file.attribute.Attributes

public final class Attributes
extends Object

This class consists exclusively of static methods that operate on or return the attributes of files or file stores. These methods provide for convenient use of the attribute-views defined in this package.

Since:
1.7

Method Summary
Modifier and Type Method and Description
static List<AclEntry> getAcl(FileRef file)
          Reads a file's Access Control List (ACL).
static UserPrincipal getOwner(FileRef file)
          Returns the owner of a file.
static BasicFileAttributes readBasicFileAttributes(FileRef file, LinkOption... options)
          Reads the basic file attributes of a file.
static DosFileAttributes readDosFileAttributes(FileRef file, LinkOption... options)
          Reads the DOS file attributes of a file.
static FileStoreSpaceAttributes readFileStoreSpaceAttributes(FileStore store)
          Reads the space attributes of a file store.
static PosixFileAttributes readPosixFileAttributes(FileRef file, LinkOption... options)
          Reads the POSIX file attributes of a file.
static void setAcl(FileRef file, List<AclEntry> acl)
          Updates a file's Access Control List (ACL).
static void setLastAccessTime(FileRef file, FileTime lastAccessTime)
          Updates a file's last access time attribute.
static void setLastModifiedTime(FileRef file, FileTime lastModifiedTime)
          Updates a file's last modified time attribute.
static void setOwner(FileRef file, UserPrincipal owner)
          Updates the file owner.
static void setPosixFilePermissions(FileRef file, Set<PosixFilePermission> perms)
          Sets a file's POSIX permissions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readBasicFileAttributes

public static BasicFileAttributes readBasicFileAttributes(FileRef file,
                                                          LinkOption... options)
                                                   throws IOException
Reads the basic file attributes of a file.

The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link. By default, symbolic links are followed and the file attributes of the final target of the link are read. If the option NOFOLLOW_LINKS is present then symbolic links are not followed and so the method returns the file attributes of the symbolic link itself. This option should be used where there is a need to determine if a file is a symbolic link:

    boolean isSymbolicLink = Attributes.readBasicFileAttributes(file, NOFOLLOW_LINKS).isSymbolicLink();
 

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

Parameters:
file - A file reference that locates the file
options - Options indicating how symbolic links are handled
Returns:
The basic file attributes
Throws:
IOException - If an I/O error occurs
SecurityException - In the case of the default provider, the security manager's checkRead method is invoked to check read access to file
See Also:
BasicFileAttributeView.readAttributes()

readPosixFileAttributes

public static PosixFileAttributes readPosixFileAttributes(FileRef file,
                                                          LinkOption... options)
                                                   throws IOException
Reads the POSIX file attributes of a file.

The file parameter locates a file that supports the PosixFileAttributeView. This file attribute view provides access to a subset 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. It is implementation specific if all file attributes are read as an atomic operation with respect to other file system operations.

The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link. By default, symbolic links are followed and the file attributes of the final target of the link are read. If the option NOFOLLOW_LINKS is present then symbolic links are not followed and so the method returns the file attributes of the symbolic link itself.

Parameters:
file - A file reference that locates the file
options - Options indicating how symbolic links are handled
Returns:
The POSIX file attributes
Throws:
UnsupportedOperationException - If the PosixFileAttributeView is not available
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 checkRead method denies read access to the file.
See Also:
PosixFileAttributeView.readAttributes()

readDosFileAttributes

public static DosFileAttributes readDosFileAttributes(FileRef file,
                                                      LinkOption... options)
                                               throws IOException
Reads the DOS file attributes of a file.

The file parameter locates a file that supports the DosFileAttributeView. This file attribute view provides access to legacy "DOS" attributes supported by the file systems such as File Allocation Table (FAT), commonly used in consumer devices. It is implementation specific if all file attributes are read as an atomic operation with respect to other file system operations.

The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link. By default, symbolic links are followed and the file attributes of the final target of the link are read. If the option NOFOLLOW_LINKS is present then symbolic links are not followed and so the method returns the file attributes of the symbolic link itself.

Parameters:
file - A file reference that locates the file
options - Options indicating how symbolic links are handled
Returns:
The DOS file attributes
Throws:
UnsupportedOperationException - If the DosFileAttributeView is not available
IOException - If an I/O error occurs
SecurityException - In the case of the default provider, the security manager's checkRead method is invoked to check read access to file
See Also:
DosFileAttributeView.readAttributes()

getOwner

public static UserPrincipal getOwner(FileRef file)
                              throws IOException
Returns the owner of a file.

The file parameter locates a file that supports the FileOwnerAttributeView. This file attribute view provides access to a file attribute that is the owner of the file.

Parameters:
file - A file reference that locates the file
Returns:
A user principal representing the owner of the file
Throws:
UnsupportedOperationException - If the FileOwnerAttributeView is not available
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 checkRead method denies read access to the file.
See Also:
FileOwnerAttributeView.getOwner()

setOwner

public static void setOwner(FileRef file,
                            UserPrincipal owner)
                     throws IOException
Updates the file owner.

The file parameter locates a file that supports the FileOwnerAttributeView. This file attribute view provides access to a file attribute that is the owner of the file.

Parameters:
file - A file reference that locates the file
owner - The new file owner
Throws:
UnsupportedOperationException - If the FileOwnerAttributeView is not available
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.
See Also:
FileOwnerAttributeView.setOwner(java.nio.file.attribute.UserPrincipal)

getAcl

public static List<AclEntry> getAcl(FileRef file)
                             throws IOException
Reads a file's Access Control List (ACL).

The file parameter locates a file that supports the AclFileAttributeView. This file attribute view provides access to ACLs based on the ACL model specified in RFC 3530.

Parameters:
file - A file reference that locates the file
Returns:
An ordered list of entries representing the ACL. The returned list is modifiable.
Throws:
UnsupportedOperationException - If the AclAttributeView is not available
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 checkRead method denies read access to the file.
See Also:
AclFileAttributeView.getAcl()

setAcl

public static void setAcl(FileRef file,
                          List<AclEntry> acl)
                   throws IOException
Updates a file's Access Control List (ACL).

The file parameter locates a file that supports the AclFileAttributeView. This file attribute view provides access to ACLs based on the ACL model specified in RFC 3530.

Parameters:
file - A file reference that locates the file
acl - The new file ACL
Throws:
UnsupportedOperationException - If the AclFileAttributeView is not available
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.
See Also:
AclFileAttributeView.setAcl(java.util.List)

setLastModifiedTime

public static void setLastModifiedTime(FileRef file,
                                       FileTime lastModifiedTime)
                                throws IOException
Updates a file's last modified time attribute. The file time is converted to the epoch and precision supported by the file system. Converting from finer to coarser granularities result in precision loss. The behavior of this method when attempting to set a timestamp to a value that is outside the range supported by the underlying file store is not defined. It may or not fail by throwing an IOException.

If the file system does not support a last modified time attribute then this method has no effect.

Usage Example: Suppose we want to set the last modified time to the current time:

    FileTime now = FileTime.fromMillis(System.currentTimeMillis());
    Attributes.setLastModifiedTime(file, now);
 

Parameters:
file - A file reference that locates the file
lastModifiedTime - The new last modified time
Throws:
IOException - If an I/O error occurs
SecurityException - In the case of the default provider, the security manager's checkWrite method is invoked to check write access to file
See Also:
BasicFileAttributeView.setTimes(java.nio.file.attribute.FileTime, java.nio.file.attribute.FileTime, java.nio.file.attribute.FileTime)

setLastAccessTime

public static void setLastAccessTime(FileRef file,
                                     FileTime lastAccessTime)
                              throws IOException
Updates a file's last access time attribute. The file time is converted to the epoch and precision supported by the file system. Converting from finer to coarser granularities result in precision loss. The behavior of this method when attempting to set a timestamp to a value that is outside the range supported by the underlying file store is not defined. It may or not fail by throwing an IOException.

If the file system does not support a last access time attribute then this method has no effect.

Parameters:
file - A file reference that locates the file
lastAccessTime - The new last access time
Throws:
IOException - If an I/O error occurs
SecurityException - In the case of the default provider, the security manager's checkWrite method is invoked to check write access to file
See Also:
BasicFileAttributeView.setTimes(java.nio.file.attribute.FileTime, java.nio.file.attribute.FileTime, java.nio.file.attribute.FileTime)

setPosixFilePermissions

public static void setPosixFilePermissions(FileRef file,
                                           Set<PosixFilePermission> perms)
                                    throws IOException
Sets a file's POSIX permissions.

The file parameter is a reference to an existing file. It supports the PosixFileAttributeView that provides access to file attributes commonly associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards.

Parameters:
file - A file reference that locates the file
perms - The new set of permissions
Throws:
UnsupportedOperationException - If PosixFileAttributeView is not available
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, and a security manager is installed, it denies RuntimePermission("accessUserInformation") or its checkWrite method denies write access to the file.
See Also:
PosixFileAttributeView.setPermissions(java.util.Set)

readFileStoreSpaceAttributes

public static FileStoreSpaceAttributes readFileStoreSpaceAttributes(FileStore store)
                                                             throws IOException
Reads the space attributes of a file store.

The store parameter is a file store that supports the FileStoreSpaceAttributeView providing access to the space related attributes of the file store. It is implementation specific if all attributes are read as an atomic operation with respect to other file system operations.

Parameters:
store - The file store
Returns:
The file store space attributes
Throws:
UnsupportedOperationException - If the file store space attribute view is not supported
IOException - If an I/O error occurs
See Also:
FileStoreSpaceAttributeView.readAttributes()

Java™ Platform
Standard Ed. 7

DRAFT ea-b118

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 1993, 2010, Oracle Corporation. All rights reserved.
DRAFT ea-b118

Scripting on this page tracks web page traffic, but does not change the content in any way.