@Test public void testResourcesFromPath() throws Exception { final List<String> paths = Classpaths.resources(this.getClass(), "/org/node/file1.txt"); String path = paths.get(0); boolean ok = true; ok |= Str.in("abc", IO.read(path)) || die(); }
public static String readFromClasspath(Class<?> clazz, String location) { List<Path> resources = Classpaths.resources(clazz, location); if (len(resources) > 0) { try { return read(Files.newBufferedReader(resources.get(0), DEFAULT_CHARSET)); } catch (IOException e) { return Exceptions.handle(String.class, "unable to read classpath resource " + location, e); } } else { return null; } }
public static Path path(String location) { if (!location.startsWith(CLASSPATH_SCHEMA + ":")) { return Paths.get(location); } else { String path = StringScanner.split(location, ':')[1]; final List<Path> resources = Classpaths.resources(IO.class, path); Path result = Lists.idx(resources, 0); if (result == null) { return path(path); } return result; } }
private static List<String> listFromDefaultClassLoader(String s) { List<String> result = new ArrayList<>(); String newPath = s; final List<Path> resources = Classpaths.resources(IO.class, newPath); for (Path resourcePath : resources) { if (Files.isDirectory(resourcePath)) { result.addAll(IO.list(resourcePath)); } else { result.add(resourcePath.toString()); } } // for ( int index = 0; index < result.size(); index++ ) { // result.set( index, "classpath:" + result.get( index ) ); // } return result; }