< prev index next >

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

Print this page
rev 13123 : 8132734: JDK 9 runtime changes to support multi-release jar files
Summary: JEP 238 Multi-Release JAR Files runtime support
Contributed-by: steve.drach@oracle.com
rev 12807 : 8137056: Move SharedSecrets and interface friends out of sun.misc
Reviewed-by: alanb, mchung, psandoz, rriggs
rev 11804 : 8078467: Update core libraries to use diamond with anonymous classes
Reviewed-by: mchung, alanb
rev 11051 : 8049367: Modular Run-Time Images
Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore
Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@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, sundararajan.athijegannathan@oracle.com
rev 10469 : 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


 681 
 682         JarFile getJarFile () {
 683             return jar;
 684         }
 685 
 686         private boolean isOptimizable(URL url) {
 687             return "file".equals(url.getProtocol());
 688         }
 689 
 690         private void ensureOpen() throws IOException {
 691             if (jar == null) {
 692                 try {
 693                     java.security.AccessController.doPrivileged(
 694                         new java.security.PrivilegedExceptionAction<>() {
 695                             public Void run() throws IOException {
 696                                 if (DEBUG) {
 697                                     System.err.println("Opening " + csu);
 698                                     Thread.dumpStack();
 699                                 }
 700 
 701                                 jar = getJarFile(csu);
 702                                 index = JarIndex.getJarIndex(jar, metaIndex);
 703                                 if (index != null) {
 704                                     String[] jarfiles = index.getJarFiles();
 705                                 // Add all the dependent URLs to the lmap so that loaders
 706                                 // will not be created for them by URLClassPath.getLoader(int)
 707                                 // if the same URL occurs later on the main class path.  We set
 708                                 // Loader to null here to avoid creating a Loader for each
 709                                 // URL until we actually need to try to load something from them.
 710                                     for(int i = 0; i < jarfiles.length; i++) {
 711                                         try {
 712                                             URL jarURL = new URL(csu, jarfiles[i]);
 713                                             // If a non-null loader already exists, leave it alone.
 714                                             String urlNoFragString = URLUtil.urlNoFragString(jarURL);
 715                                             if (!lmap.containsKey(urlNoFragString)) {
 716                                                 lmap.put(urlNoFragString, null);
 717                                             }
 718                                         } catch (MalformedURLException e) {
 719                                             continue;
 720                                         }
 721                                     }


 765          * Returns the index of this JarLoader if it exists.
 766          */
 767         JarIndex getIndex() {
 768             try {
 769                 ensureOpen();
 770             } catch (IOException e) {
 771                 throw new InternalError(e);
 772             }
 773             return index;
 774         }
 775 
 776         /*
 777          * Creates the resource and if the check flag is set to true, checks if
 778          * is its okay to return the resource.
 779          */
 780         Resource checkResource(final String name, boolean check,
 781             final JarEntry entry) {
 782 
 783             final URL url;
 784             try {
 785                 url = new URL(getBaseURL(), ParseUtil.encodePath(name, false));


 786                 if (check) {
 787                     URLClassPath.check(url);
 788                 }
 789             } catch (MalformedURLException e) {
 790                 return null;
 791                 // throw new IllegalArgumentException("name");
 792             } catch (IOException e) {
 793                 return null;
 794             } catch (AccessControlException e) {
 795                 return null;
 796             }
 797 
 798             return new Resource() {
 799                 public String getName() { return name; }
 800                 public URL getURL() { return url; }
 801                 public URL getCodeSourceURL() { return csu; }
 802                 public InputStream getInputStream() throws IOException
 803                     { return jar.getInputStream(entry); }
 804                 public int getContentLength()
 805                     { return (int)entry.getSize(); }




 681 
 682         JarFile getJarFile () {
 683             return jar;
 684         }
 685 
 686         private boolean isOptimizable(URL url) {
 687             return "file".equals(url.getProtocol());
 688         }
 689 
 690         private void ensureOpen() throws IOException {
 691             if (jar == null) {
 692                 try {
 693                     java.security.AccessController.doPrivileged(
 694                         new java.security.PrivilegedExceptionAction<>() {
 695                             public Void run() throws IOException {
 696                                 if (DEBUG) {
 697                                     System.err.println("Opening " + csu);
 698                                     Thread.dumpStack();
 699                                 }
 700 
 701                                 jar = getJarFile(csu).setRuntimeVersioned();
 702                                 index = JarIndex.getJarIndex(jar, metaIndex);
 703                                 if (index != null) {
 704                                     String[] jarfiles = index.getJarFiles();
 705                                 // Add all the dependent URLs to the lmap so that loaders
 706                                 // will not be created for them by URLClassPath.getLoader(int)
 707                                 // if the same URL occurs later on the main class path.  We set
 708                                 // Loader to null here to avoid creating a Loader for each
 709                                 // URL until we actually need to try to load something from them.
 710                                     for(int i = 0; i < jarfiles.length; i++) {
 711                                         try {
 712                                             URL jarURL = new URL(csu, jarfiles[i]);
 713                                             // If a non-null loader already exists, leave it alone.
 714                                             String urlNoFragString = URLUtil.urlNoFragString(jarURL);
 715                                             if (!lmap.containsKey(urlNoFragString)) {
 716                                                 lmap.put(urlNoFragString, null);
 717                                             }
 718                                         } catch (MalformedURLException e) {
 719                                             continue;
 720                                         }
 721                                     }


 765          * Returns the index of this JarLoader if it exists.
 766          */
 767         JarIndex getIndex() {
 768             try {
 769                 ensureOpen();
 770             } catch (IOException e) {
 771                 throw new InternalError(e);
 772             }
 773             return index;
 774         }
 775 
 776         /*
 777          * Creates the resource and if the check flag is set to true, checks if
 778          * is its okay to return the resource.
 779          */
 780         Resource checkResource(final String name, boolean check,
 781             final JarEntry entry) {
 782 
 783             final URL url;
 784             try {
 785                 // add #runtime fragment to tell JarURLConnection to use
 786                 // runtime versioning if the underlying jar file is multi-release
 787                 url = new URL(getBaseURL(), ParseUtil.encodePath(name, false) + "#runtime");
 788                 if (check) {
 789                     URLClassPath.check(url);
 790                 }
 791             } catch (MalformedURLException e) {
 792                 return null;
 793                 // throw new IllegalArgumentException("name");
 794             } catch (IOException e) {
 795                 return null;
 796             } catch (AccessControlException e) {
 797                 return null;
 798             }
 799 
 800             return new Resource() {
 801                 public String getName() { return name; }
 802                 public URL getURL() { return url; }
 803                 public URL getCodeSourceURL() { return csu; }
 804                 public InputStream getInputStream() throws IOException
 805                     { return jar.getInputStream(entry); }
 806                 public int getContentLength()
 807                     { return (int)entry.getSize(); }


< prev index next >