Fwd: questions about mandatory/optional file attributes
Vince Bonfanti
vbonfanti at gmail.com
Tue Sep 1 05:52:56 PDT 2009
I understand about the bulk read of attributes. My point is, if my
Path implementation is required to support the following, which must
return a non-null Boolean:
Path.getAttribute( "isDirectory" );
then it's trivial to provide an "isDirectory" method, which can be
implemented entirely based on the above getAttribute call:
public boolean isDirectory( LinkOption ... options ) {
return ((Boolean)getAttribute( "isDirectory", options )).booleanValue();
}
The same is true for all of the mandatory attributes. Therefore, I
can't see any reason not to provide type-safe accessors for all of the
mandatory attributes directly on the Path class (probably via the
FileRef interface).
Vince
>
>> 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