@Test public void listsByPathAndSuffix() { ClassLoader classLoader = ClasspathResourceIndexTest.class.getClassLoader(); ClasspathResourceIndex index = new ClasspathResourceIndex(classLoader); Iterable<Resource> resources = index.list("com/hotels/styx/common/io", ".txt"); assertThat(resources, containsInAnyOrder( resourceWithPath("resource.txt"), resourceWithPath("subdirectory/subdir-resource.txt") )); }
@Override public Iterable<Resource> list(String path, String suffix) { String classpath = path.replace("classpath:", ""); ResourceIteratorFactory resourceIteratorFactory = new DelegatingResourceIteratorFactory(); try { Enumeration<URL> resources = classLoader.getResources(classpath); return enumerationStream(resources) .map(url -> resourceIteratorFactory.createIterator(url, classpath, suffix)) .flatMap(ClasspathResourceIndex::iteratorStream) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } }
ClasspathResourceIndex implements ResourceIndex { @Override public Iterable<Resource> list(String path, String suffix) { String classpath = path.replace("classpath:", ""); ResourceIteratorFactory resourceIteratorFactory = new DelegatingResourceIteratorFactory(); try { Enumeration<URL> resources = classLoader.getResources(classpath); return enumerationStream(resources) .map(url -> resourceIteratorFactory.createIterator(url, classpath, suffix)) .flatMap(ClasspathResourceIndex::iteratorStream) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } } }
ClasspathResourceIndex implements ResourceIndex { @Override public Iterable<Resource> list(String path, String suffix) { String classpath = path.replace("classpath:", ""); ResourceIteratorFactory resourceIteratorFactory = new DelegatingResourceIteratorFactory(); try { Enumeration<URL> resources = classLoader.getResources(classpath); return enumerationStream(resources) .map(url -> resourceIteratorFactory.createIterator(url, classpath, suffix)) .flatMap(ClasspathResourceIndex::iteratorStream) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } } ClasspathResourceIndex(ClassLoader classLoader); }
ClasspathResourceIndex implements ResourceIndex { @Override public Iterable<Resource> list(String path, String suffix) { String classpath = path.replace("classpath:", ""); ResourceIteratorFactory resourceIteratorFactory = new DelegatingResourceIteratorFactory(); try { Enumeration<URL> resources = classLoader.getResources(classpath); return enumerationStream(resources) .map(url -> resourceIteratorFactory.createIterator(url, classpath, suffix)) .flatMap(ClasspathResourceIndex::iteratorStream) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } } ClasspathResourceIndex(ClassLoader classLoader); @Override Iterable<Resource> list(String path, String suffix); }
ClasspathResourceIndex implements ResourceIndex { @Override public Iterable<Resource> list(String path, String suffix) { String classpath = path.replace("classpath:", ""); ResourceIteratorFactory resourceIteratorFactory = new DelegatingResourceIteratorFactory(); try { Enumeration<URL> resources = classLoader.getResources(classpath); return enumerationStream(resources) .map(url -> resourceIteratorFactory.createIterator(url, classpath, suffix)) .flatMap(ClasspathResourceIndex::iteratorStream) .collect(toList()); } catch (IOException e) { throw new RuntimeException(e); } } ClasspathResourceIndex(ClassLoader classLoader); @Override Iterable<Resource> list(String path, String suffix);  }