コード例 #1
0
ファイル: IO.java プロジェクト: nremond/boon
  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;
  }
コード例 #2
0
ファイル: ClasspathsTest.java プロジェクト: karlguzman/boon
  @Test
  public void testFileResources2() throws Exception {
    String someResource = "/org/node/resource.txt";

    File file = new File("files/node-1.0-SNAPSHOT.jar");
    URL url1 = file.getAbsoluteFile().toURI().toURL();
    URL url2 = new File("files/invoke-1.0-SNAPSHOT.jar").getAbsoluteFile().toURI().toURL();

    URLClassLoader loader = new URLClassLoader(new URL[] {url1, url2});

    final List<String> resourcePaths = Classpaths.listFromClassLoader(loader, someResource);

    List<Path> list = IO.paths("classpath://org/node/");

    // List<Path> list = Classpaths.pathsFromClassLoader(loader, someResource);

    puts(multiply('-', 10), "Path ");
    for (Path path : list) {

      puts(path, path.getFileSystem(), path.getClass().getName());
      if (path.toString().endsWith(".txt")) {
        puts(IO.readPath(path));
      }
    }

    puts(multiply('-', 10), "String Path ");
    List<String> slist = IO.list("classpath://org/node/");

    for (String spath : slist) {

      puts(spath);
      if (spath.toString().endsWith(".txt")) {
        puts(IO.readResource(spath));
      }
    }
  }