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

Zhong Yu zhong.j.yu at gmail.com
Wed Aug 22 16:50:23 PDT 2012


On Wed, Aug 22, 2012 at 6:33 PM, Ulf Zibis <Ulf.Zibis at cosoco.de> wrote:
> 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");
>             }
>         }

That'll leave r==null if `modes` is empty. But an empty `modes` is
supposed to be equivalent to [READ].


>         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