questions about mandatory/optional file attributes
Alan Bateman
Alan.Bateman at Sun.COM
Tue Sep 1 01:46:04 PDT 2009
Vince Bonfanti wrote:
> :
>
> optional: lastModifiedTime(), lastAccessTime(), creationTime(), fileKey()
> mandatory: isRegularFile(), isDirectory(), isSymbolicLink(), isOther(), size()
>
> Question #1: Is this list of mandatory/optional attributes correct?
>
Yes, although the isXXX methods are to query the file type, which
doesn't have its own type in the API. In other words, the required
attributes are the "file type" and the size.
> Specifically, if my file system implementation does not support
> symbolic links, am I supposed to return a boolean for
> isSymbolicLink(), rather than throwing UnsupportedOperationException?
>
If your provider doesn't support symbolic links then isSymbolicLink will
return false. If you have access to Windows XP or Windows Server 2003
then you try this out.
> :
>
> Question #2: Does "supported" in the FileRef javadocs take the same
> meaning as "mandatory" on the BasisFileAttributes javadocs?
> Specifically, if my file system implementation does not support
> symbolic links, am I supposed to return a Boolean from
> FileRef.getAttribute( "isSymbolicLink" ), rather than returning null?
>
Yes, return Boolean.FALSE (not null, because the "file type" is a
required attribute). We should probably add an additional column to the
table in BasicFileAttributeView to make this clearer.
> Finally, it appears there are no direct equivalents to
> java.io.File.isDirectory(), isFile(), lastModified() or length() in
> the java.nio.file.Path class. For example, the two most direct ways I
> can find in NIO2 to do the equivalent of java.io.File.isDirectory()
> are:
>
> Attributes.readBasicFileAttributes( myPath ).isDirectory();
> ((Boolean)myPath.readAttribute( "isDirectory" )).booleanValue();
>
The basic attributes are read in bulk for performance reasons (as it is
very common to require several attributes of the same file at around the
same time). Luckily, many of the reasons to need to test the file type
go away with the new API. However, if really needed, we can add helper
methods to the Attributes class.
-Alan.
More information about the nio-discuss
mailing list