Get the URLs for the directory and all libraries located in the directory
@param directory The directory
@return The URLs
@exception MalformedURLException MalformedURLException
@exception IOException IOException
429835
protected URL[] getUrls(File directory) throws MalformedURLException, IOException
   {
      List<URL> list = new LinkedList<URL>();

      if (directory.exists() && directory.isDirectory())
      {
         // Add directory
         list.add(directory.toURI().toURL());

         // Add the contents of the directory too
         File[] jars = directory.listFiles(new JarFilter());

         if (jars != null)
         {
            for (int j = 0; j < jars.length; j++)
            {
               list.add(jars[j].getCanonicalFile().toURI().toURL());
            }
         }
      }
      return list.toArray(new URL[list.size()]);
   }
516053
@Pure
	public static URL dirname(File filename) {
		if (filename == null) {
			return null;
		}
		String parent = fromFileStandardToURLStandard(filename.getParent());
		try {
			if (parent == null || "".equals(parent)) { //$NON-NLS-1$
				if (filename.isAbsolute()) {
					return null;
				}
				return new URL(URISchemeType.FILE.name(), "", CURRENT_DIRECTORY); //$NON-NLS-1$
			}
			// Treat Windows specific.
			if (Pattern.matches("^" + URL_PATH_SEPARATOR + "?[a-zA-Z][:|]$", parent)) { //$NON-NLS-1$ //$NON-NLS-2$
				parent += URL_PATH_SEPARATOR;
			}
			return new URL(URISchemeType.FILE.name(), "", parent); //$NON-NLS-1$
		} catch (MalformedURLException exception) {
			return null;
		}
	}
1089647
public static String unpack(String directory) {
        File file = unpack(new File(directory));
        return file.getAbsolutePath();
    }
1205409
@Override
  public Set<String> getDirectoryEntries() throws
      IOException
  {
    synchronized (zip)
    {
      if (allEntries == null)
      {
        listEntries();
      }
      return Collections.unmodifiableSet(dirEntries);
    }
  }
200946
public List<URL> getURLs() {
        final List<URL> resourceURLs = new ArrayList<>(this.size());
        for (final Resource resource : this) {
            resourceURLs.add(resource.getURL());
        }
        return resourceURLs;
    }
1270109
public List<URL> getManagedURLs()
    {
        // should we cache it?
        List<URL> managedURL = getJarFileUrls();
        if (managedURL == null)
        {
            managedURL = new ArrayList<URL>(1);
        }

        if (!getExcludeUnlistedClasses())
        {
            managedURL.add(getPersistenceUnitRootUrl());
        }
        return managedURL;
    }
438975
public static File getJavaTools() throws MalformedURLException {
        File javaToolsFile = null;
        String javaHome = System.getProperty("java.home");

        //if the tools.jar can't be found under the java home, then goto java home's parent and try again.
        //this case would happen when user set the jre as the java home.
        if (null != javaHome && !javaHome.isEmpty()) {
            File javaHomeFile = new File(javaHome);
            javaToolsFile = buildJavaToolsFile(javaHomeFile);
            if (null == javaToolsFile) {
                javaToolsFile = buildJavaToolsFile(javaHomeFile.getParentFile());
            }
        }

        return javaToolsFile;
    }
365498
private void findFiles(File directory) throws IOException, ClassNotFoundException {

        File[] files = directory.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".class");
            }
        });

        if (files != null) {
            for (File file : files) {
                int current = currentDirectoryPath.length();
                String fileName = file.getCanonicalPath().substring(++current);
                String className = fileName.replace(File.separatorChar, '.').substring(0, fileName.length() - 6);
                tryClass(className);
            }
        }
    }
781066
public String []list() throws IOException
  {
    ArrayList<String> list = new ArrayList<String>();

    String pathname = _pathname;
    // XXX:??
    if (pathname.startsWith("/"))
      pathname = "." + pathname;

    ArrayList<PathImpl> pathList = ((MergePath) _root)._pathList;
    for (int i = 0; i < pathList.size(); i++) {
      PathImpl path = pathList.get(i);

      path = path.lookup(pathname);

      if (path.isDirectory()) {
        String[]subList = path.list();

        for (int j = 0; subList != null && j < subList.length; j++) {
          if (! list.contains(subList[j]))
            list.add(subList[j]);
        }
      }
    }

    return (String []) list.toArray(new String[list.size()]);
  }
396853
@NonNull
  public static File[] listAllFiles(File directory) {
    if (directory == null) {
      return new File[0];
    }
    File[] files = directory.listFiles();
    return files != null ? files : new File[0];
  }
493756
protected boolean isDirectory(Resource directory) {
	if (directory.exists()) return directory.isDirectory();
	try {
	    directory.createDirectory(true);
	    return true;
	}
	catch (IOException e) {
	    e.printStackTrace(getErrWriter());
	}
	return false;
    }
400105
public static URL getResourceURL(String resource) throws IOException {
    URL url = null;
    ClassLoader loader = ResourcesUtils.class.getClassLoader();
    if (loader != null) {
      url = loader.getResource(resource);
    }
    if (url == null) {
      url = ClassLoader.getSystemResource(resource);
    }
    if (url == null) {
      throw new IOException("Could not find resource " + resource);
    }
    return url;
  }
1244760
public static void loadLibraryFromFile(final String directory, final String filename) throws IOException {

		final String libraryPath = directory + File.separator + filename;

		synchronized (loadedLibrarySet) {

			final File outputFile = new File(directory, filename);
			if (!outputFile.exists()) {

				// Try to extract the library from the system resources
				final ClassLoader cl = ClassLoader.getSystemClassLoader();
				final InputStream in = cl.getResourceAsStream(JAR_PREFIX + filename);
				if (in == null) {
					throw new IOException("Unable to extract native library " + filename + " to " + directory);
				}

				final OutputStream out = new FileOutputStream(outputFile);
				copy(in, out);
			}

			System.load(libraryPath);
			loadedLibrarySet.add(filename);
		}
	}
1329030
public static List<File> listDirs(final File dir)
	{
		final List<File> foundedDirs = new ArrayList<>();
		final File[] fileArray = dir.listFiles();
		for (final File element : fileArray)
		{
			if (element.isDirectory())
			{
				foundedDirs.add(element);
			}
		}
		return foundedDirs;

	}
471083
private ArrayList<String> getFiles(String dir, String subDir) {
    ArrayList<String> files = new ArrayList<>();
    String fullDir = subDir == null ? dir : dir + File.separator + subDir;
    File[] listOfFiles = (new File(fullDir)).listFiles();
    if (listOfFiles != null) {
      for (File file : listOfFiles) {
        String fullName = subDir == null ? file.getName() : subDir + File.separator + file.getName();
        if (file.isFile()) {
          files.add(fullName);
        } else if (file.isDirectory()) {
          files.addAll(getFiles(dir, fullName));
        }
      }
    }
    return files;
  }
569302
@Override
	public URL getResourceUrl(String fileName) {
		if (fileName == null) {
			return null;
		}
		URL resource = getClass().getResource(fileName);
		if (resource == null) {
			resource = Thread.currentThread().getContextClassLoader().getResource(fileName);
			if (resource == null) {
				resource = ClassLoader.getSystemResource(fileName);
				if (resource == null) {
					File file = new File(fileName);
					if (file.exists()) {
						try {
							resource = file.toURI().toURL();
						} catch (MalformedURLException e) {
							throw new JKException(e);
						}
					}
				}
			}
		}
		return resource;
	}
965057
public static long getDirectorySize(File directory) {
        if (!directory.exists()) {
            throw new IllegalArgumentException(directory + " does not exist");
        }

        if (!directory.isDirectory()) {
            throw new IllegalArgumentException(directory + " is not a directory");
        }
        long size = 0;
        File[] files = directory.listFiles();
        if (files == null) {
            // null if security restricted
            return 0L;
        }
        for (int i = 0; i < files.length; i++) {
            File file = files[i];

            if (file.isDirectory()) {
                size += getDirectorySize(file);
            } else {
                size += file.length();
            }
        }
        return size;
    }