@Test void findContainedResources(@TempDir final File temporaryFolder) throws Exception { final File nestedJar = createNestedJar(temporaryFolder, "org.apache.tomee:ziplock:jar:7.0.5"); try (final URLClassLoader parent = new URLClassLoader(new URL[] { nestedJar.toURI().toURL() }, Thread.currentThread().getContextClassLoader()); final ConfigurableClassLoader loader = new ConfigurableClassLoader("", new URL[0], parent, name -> true, name -> true, new String[] { "org/apache/tomee/ziplock/7.0.5/ziplock-7.0.5.jar" }, new String[0])) { final List<InputStream> containedResources = loader.findContainedResources("org/apache/ziplock/ClassLoaders.class"); containedResources.forEach(it -> { try { it.close(); } catch (final IOException e) { fail(e.getMessage()); } }); assertEquals(1, containedResources.size()); } finally { if (!nestedJar.delete()) { nestedJar.deleteOnExit(); } } }
public List<InputStream> findContainedResources(final String name) { try { return Stream.concat(ofNullable(super.findResources(name)).map(urls -> list(urls).stream().map(url -> { try { return url.openStream(); } catch (final IOException e) { throw new IllegalStateException(e); } })).orElseGet(Stream::empty), ofNullable(resources.get(name)) .map(s -> s .stream() .map(it -> it.resource) .map(ByteArrayInputStream::new) .map(InputStream.class::cast)) .orElseGet(Stream::empty)) .collect(toList()); } catch (final IOException e) { throw new IllegalStateException(e); } }
ConfigurableClassLoader extends URLClassLoader { public List<InputStream> findContainedResources(final String name) { try { return Stream.concat(ofNullable(super.findResources(name)).map(urls -> list(urls).stream().map(url -> { try { return url.openStream(); } catch (final IOException e) { throw new IllegalStateException(e); } })).orElseGet(Stream::empty), ofNullable(resources.get(name)) .map(s -> s .stream() .map(it -> it.resource) .map(ByteArrayInputStream::new) .map(InputStream.class::cast)) .orElseGet(Stream::empty)) .collect(toList()); } catch (final IOException e) { throw new IllegalStateException(e); } } }
ConfigurableClassLoader extends URLClassLoader { public List<InputStream> findContainedResources(final String name) { try { return Stream.concat(ofNullable(super.findResources(name)).map(urls -> list(urls).stream().map(url -> { try { return url.openStream(); } catch (final IOException e) { throw new IllegalStateException(e); } })).orElseGet(Stream::empty), ofNullable(resources.get(name)) .map(s -> s .stream() .map(it -> it.resource) .map(ByteArrayInputStream::new) .map(InputStream.class::cast)) .orElseGet(Stream::empty)) .collect(toList()); } catch (final IOException e) { throw new IllegalStateException(e); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); }
ConfigurableClassLoader extends URLClassLoader { public List<InputStream> findContainedResources(final String name) { try { return Stream.concat(ofNullable(super.findResources(name)).map(urls -> list(urls).stream().map(url -> { try { return url.openStream(); } catch (final IOException e) { throw new IllegalStateException(e); } })).orElseGet(Stream::empty), ofNullable(resources.get(name)) .map(s -> s .stream() .map(it -> it.resource) .map(ByteArrayInputStream::new) .map(InputStream.class::cast)) .orElseGet(Stream::empty)) .collect(toList()); } catch (final IOException e) { throw new IllegalStateException(e); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); Class<?> registerBytecode(final String name, final byte[] bytes); String[] getJvmMarkers(); void registerTransformer(final ClassFileTransformer transformer); synchronized URLClassLoader createTemporaryCopy(); @Override synchronized void close(); @Override Class<?> loadClass(final String name, final boolean resolve); @Override URL findResource(final String name); @Override Enumeration<URL> getResources(final String name); @Override URL getResource(final String name); @Override InputStream getResourceAsStream(final String name); @Override Enumeration<URL> findResources(final String name); List<InputStream> findContainedResources(final String name); }
ConfigurableClassLoader extends URLClassLoader { public List<InputStream> findContainedResources(final String name) { try { return Stream.concat(ofNullable(super.findResources(name)).map(urls -> list(urls).stream().map(url -> { try { return url.openStream(); } catch (final IOException e) { throw new IllegalStateException(e); } })).orElseGet(Stream::empty), ofNullable(resources.get(name)) .map(s -> s .stream() .map(it -> it.resource) .map(ByteArrayInputStream::new) .map(InputStream.class::cast)) .orElseGet(Stream::empty)) .collect(toList()); } catch (final IOException e) { throw new IllegalStateException(e); } } ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final String[] nestedDependencies, final String[] jvmPrefixes); private  ConfigurableClassLoader(final String id, final URL[] urls, final ClassLoader parent,
            final Predicate<String> parentFilter, final Predicate<String> childFirstFilter,
            final Map<String, Collection<Resource>> resources, final String[] jvmPrefixes); Class<?> registerBytecode(final String name, final byte[] bytes); String[] getJvmMarkers(); void registerTransformer(final ClassFileTransformer transformer); synchronized URLClassLoader createTemporaryCopy(); @Override synchronized void close(); @Override Class<?> loadClass(final String name, final boolean resolve); @Override URL findResource(final String name); @Override Enumeration<URL> getResources(final String name); @Override URL getResource(final String name); @Override InputStream getResourceAsStream(final String name); @Override Enumeration<URL> findResources(final String name); List<InputStream> findContainedResources(final String name); static final String NESTED_MAVEN_REPOSITORY; }