< prev index next >

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java

Print this page




 682          * Method overridden in sub-classes.
 683          */
 684         @Override
 685         public void close() throws IOException {
 686             if (jarfile != null) {
 687                 jarfile.close();
 688             }
 689         }
 690 
 691         /*
 692          * Returns the local class path for this loader, or null if none.
 693          */
 694         URL[] getClassPath() throws IOException {
 695             return null;
 696         }
 697     }
 698 
 699     /*
 700      * Nested class used to represent a Loader of resources from a JAR URL.
 701      */
 702     static class JarLoader extends Loader {
 703         private JarFile jar;
 704         private final URL csu;
 705         private JarIndex index;
 706         private URLStreamHandler handler;
 707         private final HashMap<String, Loader> lmap;
 708         private final AccessControlContext acc;
 709         private boolean closed = false;
 710         private static final JavaUtilZipFileAccess zipAccess =
 711                 SharedSecrets.getJavaUtilZipFileAccess();
 712 
 713         /*
 714          * Creates a new JarLoader for the specified URL referring to
 715          * a JAR file.
 716          */
 717         JarLoader(URL url, URLStreamHandler jarHandler,
 718                   HashMap<String, Loader> loaderMap,
 719                   AccessControlContext acc)
 720             throws IOException
 721         {
 722             super(new URL("jar", "", -1, url + "!/", jarHandler));
 723             csu = url;
 724             handler = jarHandler;
 725             lmap = loaderMap;
 726             this.acc = acc;
 727 
 728             ensureOpen();
 729         }
 730 
 731         @Override
 732         public void close () throws IOException {
 733             // closing is synchronized at higher level
 734             if (!closed) {
 735                 closed = true;
 736                 // in case not already open.
 737                 ensureOpen();


1176         /**
1177          * Returns true if the given input is a relative URI.
1178          */
1179         static boolean isRelative(String child) {
1180             try {
1181                 return !URI.create(child).isAbsolute();
1182             } catch (IllegalArgumentException e) {
1183                 return false;
1184             }
1185         }
1186     }
1187 
1188     /*
1189      * Nested class used to represent a loader of classes and resources
1190      * from a file URL that refers to a directory.
1191      */
1192     private static class FileLoader extends Loader {
1193         /* Canonicalized File */
1194         private File dir;
1195 
1196         FileLoader(URL url) throws IOException {



1197             super(url);
1198             if (!"file".equals(url.getProtocol())) {
1199                 throw new IllegalArgumentException("url");
1200             }
1201             String path = url.getFile().replace('/', File.separatorChar);
1202             path = ParseUtil.decode(path);
1203             dir = (new File(path)).getCanonicalFile();
1204         }
1205 
1206         /*
1207          * Returns the URL for a resource with the specified name
1208          */
1209         @Override
1210         URL findResource(final String name, boolean check) {
1211             Resource rsc = getResource(name, check);
1212             if (rsc != null) {
1213                 return rsc.getURL();
1214             }
1215             return null;
1216         }
1217 
1218         @Override
1219         Resource getResource(final String name, boolean check) {
1220             final URL url;




 682          * Method overridden in sub-classes.
 683          */
 684         @Override
 685         public void close() throws IOException {
 686             if (jarfile != null) {
 687                 jarfile.close();
 688             }
 689         }
 690 
 691         /*
 692          * Returns the local class path for this loader, or null if none.
 693          */
 694         URL[] getClassPath() throws IOException {
 695             return null;
 696         }
 697     }
 698 
 699     /*
 700      * Nested class used to represent a Loader of resources from a JAR URL.
 701      */
 702     private static class JarLoader extends Loader {
 703         private JarFile jar;
 704         private final URL csu;
 705         private JarIndex index;
 706         private URLStreamHandler handler;
 707         private final HashMap<String, Loader> lmap;
 708         private final AccessControlContext acc;
 709         private boolean closed = false;
 710         private static final JavaUtilZipFileAccess zipAccess =
 711                 SharedSecrets.getJavaUtilZipFileAccess();
 712 
 713         /*
 714          * Creates a new JarLoader for the specified URL referring to
 715          * a JAR file.
 716          */
 717         private JarLoader(URL url, URLStreamHandler jarHandler,
 718                           HashMap<String, Loader> loaderMap,
 719                           AccessControlContext acc)
 720             throws IOException
 721         {
 722             super(new URL("jar", "", -1, url + "!/", jarHandler));
 723             csu = url;
 724             handler = jarHandler;
 725             lmap = loaderMap;
 726             this.acc = acc;
 727 
 728             ensureOpen();
 729         }
 730 
 731         @Override
 732         public void close () throws IOException {
 733             // closing is synchronized at higher level
 734             if (!closed) {
 735                 closed = true;
 736                 // in case not already open.
 737                 ensureOpen();


1176         /**
1177          * Returns true if the given input is a relative URI.
1178          */
1179         static boolean isRelative(String child) {
1180             try {
1181                 return !URI.create(child).isAbsolute();
1182             } catch (IllegalArgumentException e) {
1183                 return false;
1184             }
1185         }
1186     }
1187 
1188     /*
1189      * Nested class used to represent a loader of classes and resources
1190      * from a file URL that refers to a directory.
1191      */
1192     private static class FileLoader extends Loader {
1193         /* Canonicalized File */
1194         private File dir;
1195 
1196         /*
1197          * Creates a new FileLoader for the specified URL with a file protocol.
1198          */
1199         private FileLoader(URL url) throws IOException {
1200             super(url);



1201             String path = url.getFile().replace('/', File.separatorChar);
1202             path = ParseUtil.decode(path);
1203             dir = (new File(path)).getCanonicalFile();
1204         }
1205 
1206         /*
1207          * Returns the URL for a resource with the specified name
1208          */
1209         @Override
1210         URL findResource(final String name, boolean check) {
1211             Resource rsc = getResource(name, check);
1212             if (rsc != null) {
1213                 return rsc.getURL();
1214             }
1215             return null;
1216         }
1217 
1218         @Override
1219         Resource getResource(final String name, boolean check) {
1220             final URL url;


< prev index next >