< prev index next >

src/java.base/windows/classes/java/io/WinNTFileSystem.java

Print this page
rev 17392 : [mq]: 8182710.01
rev 17391 : 8182710: File.listRoots() always returns the root of CD drive
Summary: Include only logical drives with an extant filesystem location
Reviewed-by: XXX
rev 16471 : 8153250: java.io.File does not handle Windows paths of the form "D:" (no path) correctly
Summary: When resolving a child to a parent, do not insert a file separator for Windows directory-relative paths
Reviewed-by: rriggs
rev 16362 : 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
Summary: Truncate the prefix, suffix, random characters per the specification
Reviewed-by: rriggs
rev 14359 : 8155775: Re-examine naming of privileged methods to access System properties
Reviewed-by: mullan
rev 14265 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs, chegar, weijun
rev 12301 : 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
Reviewed-by: martin
rev 10444 : 8054834: Modular Source Code
Reviewed-by: alanb, chegar, ihse, mduigou
Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com

@@ -27,10 +27,11 @@
 
 import java.io.File;
 import java.nio.file.Path;
 import java.util.Locale;
 import java.util.Properties;
+import java.util.stream.IntStream;
 import sun.security.action.GetPropertyAction;
 
 /**
  * Unicode-aware FileSystem for Windows NT/2000.
  *

@@ -585,26 +586,16 @@
     /* -- Filesystem interface -- */
 
     @Override
     public File[] listRoots() {
         int ds = listRoots0();
-        int n = 0;
-        for (int i = 0; i < 26; i++) {
-            if (((ds >> i) & 1) != 0) {
-                if (!access((char)('A' + i) + ":" + slash))
-                    ds &= ~(1 << i);
-                else
-                    n++;
-            }
-        }
-        File[] fs = new File[n];
-        int j = 0;
-        char slash = this.slash;
-        for (int i = 0; i < 26; i++) {
-            if (((ds >> i) & 1) != 0)
-                fs[j++] = new File((char)('A' + i) + ":" + slash);
-        }
+        File[] fs = 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);
         return fs;
     }
 
     private static native int listRoots0();
 
< prev index next >