src/java.base/share/classes/sun/misc/URLClassPath.java

Print this page
rev 13943 : 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
Reviewed-by: alanb


 384                         return new JarLoader(url, jarHandler, lmap);
 385                     }
 386                 }
 387             });
 388         } catch (java.security.PrivilegedActionException pae) {
 389             throw (IOException)pae.getException();
 390         }
 391     }
 392 
 393     /*
 394      * Pushes the specified URLs onto the list of unopened URLs.
 395      */
 396     private void push(URL[] us) {
 397         synchronized (urls) {
 398             for (int i = us.length - 1; i >= 0; --i) {
 399                 urls.push(us[i]);
 400             }
 401         }
 402     }
 403 
 404     /**
 405      * Convert class path specification into an array of file URLs.
 406      *
 407      * The path of the file is encoded before conversion into URL
 408      * form so that reserved characters can safely appear in the path.
 409      */
 410     public static URL[] pathToURLs(String path) {
 411         StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
 412         URL[] urls = new URL[st.countTokens()];
 413         int count = 0;
 414         while (st.hasMoreTokens()) {
 415             File f = new File(st.nextToken());
 416             try {
 417                 f = new File(f.getCanonicalPath());
 418             } catch (IOException x) {
 419                 // use the non-canonicalized filename
 420             }
 421             try {
 422                 urls[count++] = ParseUtil.fileToEncodedURL(f);
 423             } catch (IOException x) { }
 424         }
 425 
 426         if (urls.length != count) {
 427             URL[] tmp = new URL[count];
 428             System.arraycopy(urls, 0, tmp, 0, count);
 429             urls = tmp;
 430         }
 431         return urls;
 432     }
 433 
 434     /*
 435      * Check whether the resource URL should be returned.
 436      * Return null on security check failure.
 437      * Called by java.net.URLClassLoader.
 438      */
 439     public static URL checkURL(URL url) {
 440         if (url != null) {
 441             try {
 442                 check(url);
 443             } catch (Exception e) {
 444                 return null;
 445             }
 446         }
 447         return url;
 448     }
 449 
 450     /*
 451      * Check whether the resource URL should be returned.
 452      * Throw exception on failure.
 453      * Called internally within this file.




 384                         return new JarLoader(url, jarHandler, lmap);
 385                     }
 386                 }
 387             });
 388         } catch (java.security.PrivilegedActionException pae) {
 389             throw (IOException)pae.getException();
 390         }
 391     }
 392 
 393     /*
 394      * Pushes the specified URLs onto the list of unopened URLs.
 395      */
 396     private void push(URL[] us) {
 397         synchronized (urls) {
 398             for (int i = us.length - 1; i >= 0; --i) {
 399                 urls.push(us[i]);
 400             }
 401         }
 402     }
 403 






























 404     /*
 405      * Check whether the resource URL should be returned.
 406      * Return null on security check failure.
 407      * Called by java.net.URLClassLoader.
 408      */
 409     public static URL checkURL(URL url) {
 410         if (url != null) {
 411             try {
 412                 check(url);
 413             } catch (Exception e) {
 414                 return null;
 415             }
 416         }
 417         return url;
 418     }
 419 
 420     /*
 421      * Check whether the resource URL should be returned.
 422      * Throw exception on failure.
 423      * Called internally within this file.