Hi Brian,

On 06/23/2017 11:56 PM, Brian Burkhalter wrote:
Please review at your convenience.

https://bugs.openjdk.java.net/browse/JDK-8182710
http://cr.openjdk.java.net/~bpb/8182710/webrev.00/

The listRoots() method invokes the GetLogicalDrives() Windows function [1] 
which may set the bit for a CD’s logical drive even if no CD is currently 
inserted which also means that the root at which the CD file system would exist 
were a CD inserted is included in the returned list even though that file 
system location does not actually exist. This change eliminates including any 
locations implied by a set bit in the return value of GetLogicalDrives() if 
that location does not exist.

Thanks,

Brian

[1] 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364972(v=vs.85).aspx

This looks good, but since this is not a performance-critical method, why not use streams?

For exmaple:

    public File[] listRoots() {
        int ds = listRoots0();
        return IntStream
            .range(0, 26)
            .filter(i -> ((ds >> i) & 1) != 0)
            .mapToObj(i -> new File((char)('A' + i) + ":" + slash))
            .filter(f -> access(f.getPath()) && f.exists())
            .toArray(File[]::new);
    }


Isn't this nicer compared to:

    public File[] listRoots() {
        int ds = listRoots0();
        ArrayList<File> fs = new ArrayList<File>(Integer.bitCount(ds));
        char slash = this.slash;
        for (int i = 0; i < 26; i++) {
            if (((ds >> i) & 1) != 0) {
                File f = new File((char)('A' + i) + ":" + slash);
                if (access(f.getPath()) && f.exists()) {
                    fs.add(f);
                }
            }
        }
        return fs.toArray(new File[fs.size()]);
    }


Regards, Peter


Reply via email to