< prev index next >

src/java.base/share/classes/sun/security/tools/PathList.java

Print this page
rev 51675 : 8207690: Parsing API for classpath and similar path strings

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -25,15 +25,13 @@
 
 package sun.security.tools;
 
 import java.io.File;
 import java.io.IOException;
-import java.lang.String;
-import java.util.StringTokenizer;
-import java.net.URL;
-import java.net.URLClassLoader;
 import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.file.Paths;
 
 /**
  * A utility class for handle path list
  *
  */

@@ -61,25 +59,14 @@
      *
      * @param path the search path string
      * @return the resulting array of directory and JAR file URLs
      */
     public static URL[] pathToURLs(String path) {
-        StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
-        URL[] urls = new URL[st.countTokens()];
-        int count = 0;
-        while (st.hasMoreTokens()) {
-            URL url = fileToURL(new File(st.nextToken()));
-            if (url != null) {
-                urls[count++] = url;
-            }
-        }
-        if (urls.length != count) {
-            URL[] tmp = new URL[count];
-            System.arraycopy(urls, 0, tmp, 0, count);
-            urls = tmp;
-        }
-        return urls;
+        return Paths.pathToStrings(path)
+                .stream()
+                .map(s -> fileToURL(new File(s)))
+                .toArray(URL[]::new);
     }
 
     /**
      * Returns the directory or JAR file URL corresponding to the specified
      * local file name.
< prev index next >