private static List extractJar()

in src/java/io/bazel/rulesscala/scalac/ScalacWorker.java [125:155]


  private static List<File> extractJar(String jarPath, String outputFolder, String[] extensions)
      throws IOException {

    List<File> outputPaths = new ArrayList<>();
    JarFile jar = new JarFile(jarPath);
    Enumeration<JarEntry> e = jar.entries();
    while (e.hasMoreElements()) {
      JarEntry file = e.nextElement();
      String thisFileName = file.getName();
      // we don't bother to extract non-scala/java sources (skip manifest)
      if (extensions != null && !matchesFileExtensions(thisFileName, extensions)) {
        continue;
      }
      File f = new File(outputFolder + File.separator + file.getName());

      if (file.isDirectory()) { // if it's a directory, create it
        f.mkdirs();
        continue;
      }

      File parent = f.getParentFile();
      parent.mkdirs();
      outputPaths.add(f);

      try (InputStream is = jar.getInputStream(file);
          OutputStream fos = new FileOutputStream(f)) {
        StreamCopy.copy(is, fos);
      }
    }
    return outputPaths;
  }