questions about mandatory/optional file attributes

Vince Bonfanti vbonfanti at gmail.com
Sat Aug 29 08:29:27 PDT 2009


The BasicFileAttributes javadoc says, "Basic file attributes are
attributes that are common to many file systems and consist of
mandatory and optional file attributes as defined by this interface."
The descriptions for lastModifiedTime(), lastAccessTime(), and
creationTime() all say they return "null if the attribute is not
supported" so it's clear that these three are optional. The
description for fileKey() says it returns "null if a file key is not
available" so it seems that's also optional. There's nothing that
explicitly says which attributes are mandatory--does that mean all
other attributes are mandatory? If so, here's my list:

      optional: lastModifiedTime(), lastAccessTime(), creationTime(), fileKey()
  mandatory: isRegularFile(), isDirectory(), isSymbolicLink(), isOther(), size()

  Question #1: Is this list of mandatory/optional attributes correct?
Specifically, if my file system implementation does not support
symbolic links, am I supposed to return a boolean for
isSymbolicLink(), rather than throwing UnsupportedOperationException?

The FileRef.getAttribute() javadoc says it returns "null if ... it
does not support reading the attribute." The FileRef.readAttributes()
javadoc says, "Attributes that are not supported are ignored and will
not be present in the returned map."

  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?

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();

These both strike me as awkward and a step backwards from java.io.File.

  Question #3: If mandatory attributes are truly mandatory, why not
provide direct type-safe accessors from the FileRef interface? After
all, if FileRef.readAttribute( "isDirectory" ) is required to return a
non-null (and, presumably, Boolean) value, why not define
FileRef.isDirectory() to return a boolean?


More information about the nio-discuss mailing list