Example #1
0
File: IO.java Project: nremond/boon
  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;
    }
  }
Example #2
0
File: IO.java Project: nremond/boon
  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;
    }
  }
Example #3
0
File: IO.java Project: 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;
  }