Code Review Request: 7168172: (fs) Files.isReadable slow on Windows

Ulf Zibis Ulf.Zibis at CoSoCo.de
Wed Aug 22 16:33:23 PDT 2012


Am 22.08.2012 20:38, schrieb Kurchi Hazra:
> However, it is faster to simply open the file being checked and close it. In the case of a 
> directory then, a DirectoryStream can be opened and closed to check the same.

I would rename checkReadAccess(WindowsPath file) to tryReadAccess(WindowsPath file)

>
> Bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7168172
> Webrev: http://cr.openjdk.java.net/~khazra/7168172/webrev.00/

I'm really wondering, why we need 3 types of file access options and have to translate up and down 
between these:
- FileOption
- AccessMode
- boolean

At least the boolean one could be saved easily and (modes.length == 0) is superfluous:

     public void checkAccess(Path obj, AccessMode... modes) throws IOException {
         AccessMode r = null;
         AccessMode w = null;
         AccessMode x = null;
         for (AccessMode mode: modes) {
             switch (mode) {
                 case READ : r = READ; break;
                 case WRITE : w = WRITE; break;
                 case EXECUTE : x = EXECUTE; break;
                 default: throw new AssertionError("Should not get here");
             }
         }

         WindowsPath file = WindowsPath.toWindowsPath(obj);

         // special-case read access to avoid needing to determine effective
         // access to file
         if (w == null && x == null) {
             tryReadAccess(file);
             return;
         }

         ...
     }

-Ulf



More information about the nio-dev mailing list