Exemple #1
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;
    }
  }
Exemple #2
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;
    }
  }
Exemple #3
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;
  }