递归获得Jar文件

@param file jar文件或者包含jar文件的目录
@return jar文件列表
761897
private static List<File> loopJar(File file) {
		return FileUtil.loopFiles(file, new FileFilter() {
			@Override
			public boolean accept(File file) {
				return isJarFile(file);
			}
		});
	}
325615
private static boolean isJarFile(File file) {
		if (false == FileUtil.isFile(file)) {
			return false;
		}
		return file.getPath().toLowerCase().endsWith(".jar");
	}
390997
public static InputStream asInputStream(File file) throws IOException {
		Validate.notNull(file, "file is null");
		return asInputStream(file.toPath());
	}
648078
public static String readTextFile(File file) {
        try {
            return readTextFile(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
1283558
private JarFile getJarFile()
    throws IOException
  {
    JarFile jarFile = null;

    isCacheValid();

    if (! _backingIsFile) {
      throw new FileNotFoundException(getBacking().getNativePath());
    }
    
    try {
      jarFile = new JarFile(getBacking().getNativePath());

        /*
        if (_backing.getNativePath().indexOf("cssparser.jar") > 0)
          System.out.println("JAR: " + _backing + " " + jarFile);
          */
    }
    catch (IOException ex) {
      if (log.isLoggable(Level.FINE))
        log.log(Level.FINE, L.l("Error opening jar file '{0}'", getBacking().getNativePath()));

      throw ex;
    }

    return jarFile;
  }
682510
public static File directory(File file) {
		Validate.exists(file);
		if(!file.isDirectory())
			throw new ParameterException("\""+file+"\" is not a directory!");
		return file;
	}
1252250
public static JarClassLoader load(File dir) {
		final JarClassLoader loader = new JarClassLoader();
		loader.addJar(dir);//查找加载所有jar
		loader.addURL(dir);//查找加载所有class
		return loader;
	}
156367
@Override
    public synchronized void onFileCreate(File file) {
        final Set<DetectedWebJar> listOfDetectedWebJarLib = isWebJar(file);
        if (listOfDetectedWebJarLib != null) {
            JarFile jar = null;
            try {
                jar = new JarFile(file);
                List<FileWebJarLib> installed = new ArrayList<>();
                for (DetectedWebJar detected : listOfDetectedWebJarLib) {
                    FileWebJarLib lib = expand(detected, jar);
                    if (lib != null) {
                        libs.add(lib);
                        installed.add(lib);
                        LOGGER.info("{} unpacked to {}", lib.name, lib.root.getAbsolutePath());
                    }
                }
                controller.addWebJarLibs(installed);
            } catch (IOException e) {
                LOGGER.error("Cannot open the jar file {}", file.getAbsolutePath(), e);
            } finally {
                IOUtils.closeQuietly(jar);
            }

        }
    }
1227794
public static Map<String, String> processArchiveManifest(final File file) throws Throwable {
        Map<String, String> manifestAttrs = null;

        if (file != null && file.isFile() && ArchiveFileType.JAR.isType(file.getPath())) {
            JarFile jarFile = null;
            try {
                jarFile = new JarFile(file);
                manifestAttrs = processArchiveManifest(jarFile);
            } finally {
                if (jarFile != null) {
                    InstallUtils.close(jarFile);
                }
            }
        }

        return manifestAttrs;
    }
14902
static String readFile(String file) {

        try {
            FileReader     reader = new FileReader(file);
            BufferedReader read   = new BufferedReader(reader);
            StringBuffer   b      = new StringBuffer();
            String         s      = null;
            int            count  = 0;

            while ((s = read.readLine()) != null) {
                count++;

                b.append(s);
                b.append('\n');
            }

            read.close();
            reader.close();

            return b.toString();
        } catch (IOException e) {
            return e.getMessage();
        }
    }
464844
public static FileObject toFileObject(File file) {
        if (file == null) {
            return null;
        }
        try {
            return getFileSystemManager().toFileObject(file);
        } catch (FileSystemException e) {
            throw new IllegalStateException(e);
        }
    }
1173603
private static File extract(File file, File directory) throws IOException
   {
      if (file == null)
         throw new IllegalArgumentException("File is null");

      if (directory == null)
         throw new IllegalArgumentException("Directory is null");

      File target = new File(directory, file.getName());

      if (target.exists())
         recursiveDelete(target);

      if (!target.mkdirs())
         throw new IOException("Could not create " + target);

      JarFile jar = null;
      try
      {
         jar = new JarFile(file);
         Enumeration<JarEntry> entries = jar.entries();

         while (entries.hasMoreElements())
         {
            JarEntry je = entries.nextElement();
            File copy = new File(target, je.getName());

            if (!je.isDirectory())
            {
               InputStream in = null;
               OutputStream out = null;

               // Make sure that the directory is _really_ there
               if (copy.getParentFile() != null && !copy.getParentFile().exists())
               {
                  if (!copy.getParentFile().mkdirs())
                     throw new IOException("Could not create " + copy.getParentFile());
               }

               try
               {
                  in = new BufferedInputStream(jar.getInputStream(je));
                  out = new BufferedOutputStream(new FileOutputStream(copy));

                  byte[] buffer = new byte[4096];
                  for (;;)
                  {
                     int nBytes = in.read(buffer);
                     if (nBytes <= 0)
                        break;

                     out.write(buffer, 0, nBytes);
                  }
                  out.flush();
               }
               finally
               {
                  try
                  {
                     if (out != null)
                        out.close();
                  }
                  catch (IOException ignore)
                  {
                     // Ignore
                  }

                  try
                  {
                     if (in != null)
                        in.close();
                  }
                  catch (IOException ignore)
                  {
                     // Ignore
                  }
               }
            }
            else
            {
               if (!copy.exists())
               {
                  if (!copy.mkdirs())
                     throw new IOException("Could not create " + copy);
               }
               else
               {
                  if (!copy.isDirectory())
                     throw new IOException(copy + " isn't a directory");
               }
            }
         }
      }
      finally
      {
         try
         {
            if (jar != null)
               jar.close();
         }
         catch (IOException ignore)
         {
            // Ignore
         }
      }

      return target;
   }
116810
private void findJarFile() throws IOException {
        if (getUseCaches()) {
            synchronized (jarCache) {
                jarFile = jarCache.get(jarFileURL);
            }
            if (jarFile == null) {
                JarFile jar = openJarFile();
                synchronized (jarCache) {
                    jarFile = jarCache.get(jarFileURL);
                    if (jarFile == null) {
                        jarCache.put(jarFileURL, jar);
                        jarFile = jar;
                    } else {
                        jar.close();
                    }
                }
            }
        } else {
            jarFile = openJarFile();
        }

        if (jarFile == null) {
            throw new IOException();
        }
    }
997957
public Jar setJarPrefix(Path file) {
        verifyNotSealed();
        if (jos != null)
            throw new IllegalStateException("Really executable cannot be set after entries are added.");
        if (file != null && jarPrefixStr != null)
            throw new IllegalStateException("A prefix has already been set (" + jarPrefixStr + ")");
        this.jarPrefixFile = file;
        return this;
    }
109442
protected String resolveJarFile() {
        Class resourceClass = resourceInfo.getResourceClass();
        if (resourceClass == null) return null;
        String classFile = resourceClass.getName().replace(".", "/") + ".class";
        URL classUrl = IOUtils.getResource(classFile);
        String urlProtocol = classUrl.getProtocol();
        if (urlProtocol.equals("jar")) {
            String path = classUrl.getPath();
            return path.substring(0, path.length() - classFile.length() - 1);
        }
        return null;
    }
540040
public static String readFile(File file) {
		FileInputStream inputStream;
		try {
			inputStream = new FileInputStream(file);
			return new String(readStream(inputStream));
		} catch (FileNotFoundException e) {
			JK.throww(e);
			return null;
		}
	}
1204041
public static URLClassLoader loadJarToSystemClassLoader(File jarFile) {
		URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
		loadJar(urlClassLoader, jarFile);
		return urlClassLoader;
	}