EngineBlockFiles { public static Optional<InputStream> findOptionalStreamOrFile(String basename, String extension, String... searchPaths) { boolean needsExtension = (extension != null && !extension.isEmpty() && !basename.endsWith("." + extension)); String filename = basename + (needsExtension ? "." + extension : ""); ArrayList<String> paths = new ArrayList<String>() {{ add(filename); if (!isRemote(basename)) { addAll(Arrays.stream(searchPaths).map(s -> s + File.separator + filename) .collect(Collectors.toCollection(ArrayList::new))); } }}; for (String path : paths) { Optional<InputStream> stream = getInputStream(path); if (stream.isPresent()) { return stream; } } return Optional.empty(); }  static InputStream findRequiredStreamOrFile(String basename, String extension, String... searchPaths); static Optional<InputStream> findOptionalStreamOrFile(String basename, String extension, String... searchPaths); static Optional<InputStream> getInputStream(String path); static String readFile(String basename);  }
@Test public void testNestedClasspathLoading() { Optional<InputStream> optionalStreamOrFile = EngineBlockFiles.findOptionalStreamOrFile("nested/testfile", "txt", "activities"); assertThat(optionalStreamOrFile).isPresent(); }