@Override public InputStream getResourceAsStream(final String path) { final ResourceList resourceList = scanResult.getResourcesWithPath(path); if (resourceList == null || resourceList.isEmpty()) { return super.getResourceAsStream(path); } else { try { return resourceList.get(0).open(); } catch (final IOException e) { return null; } } } }
/** * Fetch an {@link InputStream} for each {@link Resource} in this {@link ResourceList}, pass the * {@link InputStream} to the given {@link InputStreamConsumer}, then close the {@link InputStream} after the * {@link InputStreamConsumer} returns, by calling {@link Resource#close()}. * * @param inputStreamConsumer * The {@link InputStreamConsumer}. * @param ignoreIOExceptions * if true, any {@link IOException} thrown while trying to load any of the resources will be silently * ignored. * @throws IllegalArgumentException * if ignoreExceptions is false, and an {@link IOException} is thrown while trying to open any of * the resources. */ public void forEachInputStream(final InputStreamConsumer inputStreamConsumer, final boolean ignoreIOExceptions) { for (final Resource resource : this) { try { inputStreamConsumer.accept(resource, resource.open()); } catch (final IOException e) { if (!ignoreIOExceptions) { throw new IllegalArgumentException("Could not load resource " + resource, e); } } finally { resource.close(); } } }