|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.classpath.icedtea.java.nio.file.attribute.Attributes
public final class Attributes
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.
Method Summary | |
---|---|
static List<AclEntry> |
getAcl(FileRef file)
Reads a file's Access Control List (ACL). |
static Object |
getAttribute(FileRef file,
String attribute,
LinkOption... options)
Reads the value of a file attribute. |
static UserPrincipal |
getOwner(FileRef file)
Returns the owner of a file. |
static Map<String,?> |
readAttributes(FileRef file,
String attributes,
LinkOption... options)
Reads a set of file attributes as a bulk operation. |
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 |
setAttribute(FileRef file,
String attribute,
Object value)
Sets the value of a file attribute. |
static void |
setLastAccessTime(FileRef file,
long lastAccessTime,
TimeUnit unit)
Updates the value of a file's last access time attribute. |
static void |
setLastModifiedTime(FileRef file,
long lastModifiedTime,
TimeUnit unit)
Updates the value of 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 |
---|
public static void setAttribute(FileRef file, String attribute, Object value) throws IOException
The attribute
parameter identifies the attribute to be set
and takes the form:
[view-name:]attribute-namewhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems. attribute-name is the name of the attribute
within the set.
Usage Example: Suppose we want to set the DOS "hidden" attribute:
Attributes.setAttribute(file, "dos:hidden", true);
file
- A file reference that locates the fileattribute
- The attribute to setvalue
- The attribute value
UnsupportedOperationException
- If the attribute view is not available or it does not
support updating the attribute
IllegalArgumentException
- If the attribute value is of the correct type but has an
inappropriate value
ClassCastException
- If the attribute value is not of the expected type or is a
collection containing elements that are not of the expected
type
IOException
- If an I/O error occurs
SecurityException
- In the case of the default provider, and a security manager is
installed, its checkWrite
method denies write access to the file. If this method is invoked
to set security sensitive attributes then the security manager
may be invoked to check for additional permissions.public static Object getAttribute(FileRef file, String attribute, LinkOption... options) throws IOException
The attribute
parameter identifies the attribute to be read
and takes the form:
[view-name:]attribute-namewhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems. attribute-name is the name of the attribute.
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 attribute of the final target
of the link is read. If the option NOFOLLOW_LINKS
is present then symbolic links are not followed and so
the method returns the file attribute of the symbolic link.
Usage Example:
Suppose we require the user ID of the file owner on a system that
supports a "unix
" view:
int uid = (Integer)Attributes.getAttribute(file, "unix:uid");
file
- A file reference that locates the fileattribute
- The attribute to readoptions
- Options indicating how symbolic links are handled
null
if the attribute view
is not available or it does not support reading the attribute
IOException
- If an I/O error occurs
SecurityException
- In the case of the default provider, and a security manager is
installed, its checkRead
method denies read access to the file. If this method is invoked
to read security sensitive attributes then the security manager
may be invoked to check for additional permissions.public static Map<String,?> readAttributes(FileRef file, String attributes, LinkOption... options) throws IOException
The attributes
parameter identifies the attributes to be read
and takes the form:
[view-name:]attribute-listwhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems.
The attribute-list component is a comma separated list of
zero or more names of attributes to read. If the list contains the value
"*"
then all attributes are read. Attributes that are not supported
are ignored and will not be present in the returned map. It is
implementation specific if all attributes are read as an atomic operation
with respect to other file system operations.
The following examples demonstrate possible values for the attributes
parameter:
"*"
Read all basic-file-attributes
."size,lastModifiedTime,lastAccessTime"
Reads the file size, last modified time, and last access time attributes. "posix:*"
Read all POSIX-file-attributes
.."posix:permissions,owner,size"
Reads the POSX file permissions, owner, and file size.
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.
file
- A file reference that locates the fileattributes
- The attributes to readoptions
- Options indicating how symbolic links are handled
IOException
- If an I/O error occurs
SecurityException
- In the case of the default provider, and a security manager is
installed, its checkRead
method denies read access to the file. If this method is invoked
to read security sensitive attributes then the security manager
may be invoke to check for additional permissions.public static BasicFileAttributes readBasicFileAttributes(FileRef file, LinkOption... options) throws IOException
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. 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.
file
- A file reference that locates the fileoptions
- Options indicating how symbolic links are handled
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 fileBasicFileAttributeView.readAttributes()
public static PosixFileAttributes readPosixFileAttributes(FileRef file, LinkOption... options) throws IOException
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.
file
- A file reference that locates the fileoptions
- Options indicating how symbolic links are handled
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.PosixFileAttributeView.readAttributes()
public static DosFileAttributes readDosFileAttributes(FileRef file, LinkOption... options) throws IOException
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.
file
- A file reference that locates the fileoptions
- Options indicating how symbolic links are handled
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 fileDosFileAttributeView.readAttributes()
public static UserPrincipal getOwner(FileRef file) throws IOException
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.
file
- A file reference that locates the file
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.FileOwnerAttributeView.getOwner()
public static void setOwner(FileRef file, UserPrincipal owner) throws IOException
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.
file
- A file reference that locates the fileowner
- The new file owner
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.FileOwnerAttributeView.setOwner(org.classpath.icedtea.java.nio.file.attribute.UserPrincipal)
public static List<AclEntry> getAcl(FileRef file) throws IOException
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.
file
- A file reference that locates the file
entries
representing the
ACL. The returned list is modifiable.
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.AclFileAttributeView.getAcl()
public static void setAcl(FileRef file, List<AclEntry> acl) throws IOException
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.
file
- A file reference that locates the fileacl
- The new file ACL
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.AclFileAttributeView.setAcl(java.util.List)
public static void setLastModifiedTime(FileRef file, long lastModifiedTime, TimeUnit unit) throws IOException
The time value is measured since the epoch (00:00:00 GMT, January 1, 1970) and is converted to the precision supported by the file system. Converting from finer to coarser granularities result in precision loss.
If the file system does not support a last modified time attribute then this method has no effect.
file
- A file reference that locates the filelastModifiedTime
- The new last modified time, or -1L
to update it to
the current timeunit
- A TimeUnit
determining how to interpret the
lastModifiedTime
parameter
IllegalArgumentException
- If the lastModifiedime
parameter is a negative value other
than -1L
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 fileBasicFileAttributeView.setTimes(java.lang.Long, java.lang.Long, java.lang.Long, java.util.concurrent.TimeUnit)
public static void setLastAccessTime(FileRef file, long lastAccessTime, TimeUnit unit) throws IOException
The time value is measured since the epoch (00:00:00 GMT, January 1, 1970) and is converted to the precision supported by the file system. Converting from finer to coarser granularities result in precision loss.
If the file system does not support a last access time attribute then this method has no effect.
lastAccessTime
- The new last access time, or -1L
to update it to
the current timeunit
- A TimeUnit
determining how to interpret the
lastModifiedTime
parameter
IllegalArgumentException
- If the lastAccessTime
parameter is a negative value other
than -1L
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 fileBasicFileAttributeView.setTimes(java.lang.Long, java.lang.Long, java.lang.Long, java.util.concurrent.TimeUnit)
public static void setPosixFilePermissions(FileRef file, Set<PosixFilePermission> perms) throws IOException
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.
file
- A file reference that locates the fileperms
- The new set of permissions
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.PosixFileAttributeView.setPermissions(java.util.Set)
public static FileStoreSpaceAttributes readFileStoreSpaceAttributes(FileStore store) throws IOException
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.
store
- The file store
UnsupportedOperationException
- If the file store space attribute view is not supported
IOException
- If an I/O error occurs
SecurityException
- In the case of the default provider, and a security manager is
installed, its checkRead
method is invoked to check read access to the file used to obtain
access to the file
store, and in addition it checks RuntimePermission
("getFileStoreAttributes")FileStoreSpaceAttributeView.readAttributes()
|
NIO2 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2007, 2011, Oracle and/or its affiliates. All rights reserved.