src/java.base/share/classes/jdk/internal/loader/Loader.java
changeset 48076 794cbfa7a309
parent 47216 71c04702a3d5
child 48995 58bec53828ba
equal deleted inserted replaced
48075:c51f9eea6d2b 48076:794cbfa7a309
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    26 package jdk.internal.loader;
    26 package jdk.internal.loader;
    27 
    27 
    28 import java.io.File;
    28 import java.io.File;
    29 import java.io.FilePermission;
    29 import java.io.FilePermission;
    30 import java.io.IOException;
    30 import java.io.IOException;
    31 import java.io.UncheckedIOException;
       
    32 import java.lang.module.Configuration;
    31 import java.lang.module.Configuration;
    33 import java.lang.module.ModuleDescriptor;
    32 import java.lang.module.ModuleDescriptor;
    34 import java.lang.module.ModuleReader;
    33 import java.lang.module.ModuleReader;
    35 import java.lang.module.ModuleReference;
    34 import java.lang.module.ModuleReference;
    36 import java.lang.module.ResolvedModule;
    35 import java.lang.module.ResolvedModule;
    56 import java.util.Iterator;
    55 import java.util.Iterator;
    57 import java.util.List;
    56 import java.util.List;
    58 import java.util.Map;
    57 import java.util.Map;
    59 import java.util.Objects;
    58 import java.util.Objects;
    60 import java.util.Optional;
    59 import java.util.Optional;
    61 import java.util.Spliterator;
       
    62 import java.util.Spliterators;
       
    63 import java.util.concurrent.ConcurrentHashMap;
    60 import java.util.concurrent.ConcurrentHashMap;
    64 import java.util.function.Supplier;
       
    65 import java.util.stream.Stream;
    61 import java.util.stream.Stream;
    66 import java.util.stream.StreamSupport;
       
    67 
    62 
    68 import jdk.internal.misc.SharedSecrets;
    63 import jdk.internal.misc.SharedSecrets;
    69 import jdk.internal.module.Resources;
    64 import jdk.internal.module.Resources;
    70 
    65 
    71 
    66 
   401     public URL getResource(String name) {
   396     public URL getResource(String name) {
   402         Objects.requireNonNull(name);
   397         Objects.requireNonNull(name);
   403 
   398 
   404         // this loader
   399         // this loader
   405         URL url = findResource(name);
   400         URL url = findResource(name);
   406         if (url != null) {
   401         if (url == null) {
   407             return url;
       
   408         } else {
       
   409             // parent loader
   402             // parent loader
   410             return parent.getResource(name);
   403             if (parent != null) {
   411         }
   404                 url = parent.getResource(name);
       
   405             } else {
       
   406                 url = BootLoader.findResource(name);
       
   407             }
       
   408         }
       
   409         return url;
   412     }
   410     }
   413 
   411 
   414     @Override
   412     @Override
   415     public Enumeration<URL> getResources(String name) throws IOException {
   413     public Enumeration<URL> getResources(String name) throws IOException {
   416         Objects.requireNonNull(name);
   414         Objects.requireNonNull(name);
   417 
   415 
   418         // this loader
   416         // this loader
   419         List<URL> urls = findResourcesAsList(name);
   417         List<URL> urls = findResourcesAsList(name);
   420 
   418 
   421         // parent loader
   419         // parent loader
   422         Enumeration<URL> e = parent.getResources(name);
   420         Enumeration<URL> e;
       
   421         if (parent != null) {
       
   422             e = parent.getResources(name);
       
   423         } else {
       
   424             e = BootLoader.findResources(name);
       
   425         }
   423 
   426 
   424         // concat the URLs with the URLs returned by the parent
   427         // concat the URLs with the URLs returned by the parent
   425         return new Enumeration<>() {
   428         return new Enumeration<>() {
   426             final Iterator<URL> iterator = urls.iterator();
   429             final Iterator<URL> iterator = urls.iterator();
   427             @Override
   430             @Override
   435                 } else {
   438                 } else {
   436                     return e.nextElement();
   439                     return e.nextElement();
   437                 }
   440                 }
   438             }
   441             }
   439         };
   442         };
   440     }
       
   441 
       
   442     @Override
       
   443     public Stream<URL> resources(String name) {
       
   444         Objects.requireNonNull(name);
       
   445         // ordering not specified
       
   446         int characteristics = (Spliterator.NONNULL | Spliterator.IMMUTABLE |
       
   447                                Spliterator.SIZED | Spliterator.SUBSIZED);
       
   448         Supplier<Spliterator<URL>> supplier = () -> {
       
   449             try {
       
   450                 List<URL> urls = findResourcesAsList(name);
       
   451                 return Spliterators.spliterator(urls, characteristics);
       
   452             } catch (IOException e) {
       
   453                 throw new UncheckedIOException(e);
       
   454             }
       
   455         };
       
   456         Stream<URL> s1 = StreamSupport.stream(supplier, characteristics, false);
       
   457         Stream<URL> s2 = parent.resources(name);
       
   458         return Stream.concat(s1, s2);
       
   459     }
   443     }
   460 
   444 
   461     /**
   445     /**
   462      * Finds the resources with the given name in this class loader.
   446      * Finds the resources with the given name in this class loader.
   463      */
   447      */