Beispiel #1
0
  @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();
  }
Beispiel #2
0
  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;
    }
  }
Beispiel #3
0
  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;
    }
  }
Beispiel #4
0
  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;
  }