jdk/src/java.base/share/classes/java/lang/ClassLoader.java
changeset 42227 074dfec7f994
parent 42224 62f59542b9d8
child 42339 455e651aa073
equal deleted inserted replaced
42226:f55cb692058f 42227:074dfec7f994
  1333      *         The resource name
  1333      *         The resource name
  1334      *
  1334      *
  1335      * @return  A <tt>URL</tt> object for reading the resource, or
  1335      * @return  A <tt>URL</tt> object for reading the resource, or
  1336      *          <tt>null</tt> if the resource could not be found or the invoker
  1336      *          <tt>null</tt> if the resource could not be found or the invoker
  1337      *          doesn't have adequate  privileges to get the resource.
  1337      *          doesn't have adequate  privileges to get the resource.
       
  1338      * @throws  NullPointerException If {@code name} is {@code null}
  1338      *
  1339      *
  1339      * @since  1.1
  1340      * @since  1.1
  1340      */
  1341      */
  1341     public URL getResource(String name) {
  1342     public URL getResource(String name) {
       
  1343         Objects.requireNonNull(name);
  1342         URL url;
  1344         URL url;
  1343         if (parent != null) {
  1345         if (parent != null) {
  1344             url = parent.getResource(name);
  1346             url = parent.getResource(name);
  1345         } else {
  1347         } else {
  1346             url = BootLoader.findResource(name);
  1348             url = BootLoader.findResource(name);
  1380      *          will be empty.  Resources that the class loader doesn't have
  1382      *          will be empty.  Resources that the class loader doesn't have
  1381      *          access to will not be in the enumeration.
  1383      *          access to will not be in the enumeration.
  1382      *
  1384      *
  1383      * @throws  IOException
  1385      * @throws  IOException
  1384      *          If I/O errors occur
  1386      *          If I/O errors occur
       
  1387      * @throws  NullPointerException If {@code name} is {@code null}
  1385      *
  1388      *
  1386      * @see  #findResources(String)
  1389      * @see  #findResources(String)
  1387      *
  1390      *
  1388      * @since  1.2
  1391      * @since  1.2
  1389      */
  1392      */
  1390     public Enumeration<URL> getResources(String name) throws IOException {
  1393     public Enumeration<URL> getResources(String name) throws IOException {
       
  1394         Objects.requireNonNull(name);
  1391         @SuppressWarnings("unchecked")
  1395         @SuppressWarnings("unchecked")
  1392         Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
  1396         Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
  1393         if (parent != null) {
  1397         if (parent != null) {
  1394             tmp[0] = parent.getResources(name);
  1398             tmp[0] = parent.getResources(name);
  1395         } else {
  1399         } else {
  1432      * @return  A stream of resource {@link java.net.URL URL} objects. If no
  1436      * @return  A stream of resource {@link java.net.URL URL} objects. If no
  1433      *          resources could  be found, the stream will be empty.  Resources
  1437      *          resources could  be found, the stream will be empty.  Resources
  1434      *          that the class loader doesn't have access to will not be in the
  1438      *          that the class loader doesn't have access to will not be in the
  1435      *          stream.
  1439      *          stream.
  1436      *
  1440      *
       
  1441      * @throws  NullPointerException If {@code name} is {@code null}
       
  1442      *
  1437      * @see  #findResources(String)
  1443      * @see  #findResources(String)
  1438      *
  1444      *
  1439      * @since  9
  1445      * @since  9
  1440      */
  1446      */
  1441     public Stream<URL> resources(String name) {
  1447     public Stream<URL> resources(String name) {
       
  1448         Objects.requireNonNull(name);
  1442         int characteristics = Spliterator.NONNULL | Spliterator.IMMUTABLE;
  1449         int characteristics = Spliterator.NONNULL | Spliterator.IMMUTABLE;
  1443         Supplier<Spliterator<URL>> si = () -> {
  1450         Supplier<Spliterator<URL>> si = () -> {
  1444             try {
  1451             try {
  1445                 return Spliterators.spliteratorUnknownSize(
  1452                 return Spliterators.spliteratorUnknownSize(
  1446                     getResources(name).asIterator(), characteristics);
  1453                     getResources(name).asIterator(), characteristics);
  1598      * @param  name
  1605      * @param  name
  1599      *         The resource name
  1606      *         The resource name
  1600      *
  1607      *
  1601      * @return  An input stream for reading the resource, or <tt>null</tt>
  1608      * @return  An input stream for reading the resource, or <tt>null</tt>
  1602      *          if the resource could not be found
  1609      *          if the resource could not be found
       
  1610      * @throws  NullPointerException If {@code name} is {@code null}
  1603      *
  1611      *
  1604      * @since  1.1
  1612      * @since  1.1
  1605      */
  1613      */
  1606     public InputStream getResourceAsStream(String name) {
  1614     public InputStream getResourceAsStream(String name) {
       
  1615         Objects.requireNonNull(name);
  1607         URL url = getResource(name);
  1616         URL url = getResource(name);
  1608         try {
  1617         try {
  1609             return url != null ? url.openStream() : null;
  1618             return url != null ? url.openStream() : null;
  1610         } catch (IOException e) {
  1619         } catch (IOException e) {
  1611             return null;
  1620             return null;