Class FileUtils

java.lang.Object
com.fathzer.plugin.loader.utils.FileUtils

public class FileUtils extends Object
Some utilities about files.
  • Field Details

  • Method Details

    • getURL

      public static URL getURL(Path file)
      Gets the URL of a file
      The main difference with Path.toUri().toURL() is it encapsulate the 'more than unlikely' MalformedURLException thrown by toURL() in a UncheckedIOException, making it easy to use in a lambda expression.
      Parameters:
      file - a File
      Returns:
      an url
    • getFiles

      public static List<Path> getFiles(Path folder, int depth, BiPredicate<Path,BasicFileAttributes> matcher) throws IOException
      Gets the paths of files contained in a folder.
      Parameters:
      folder - The folder to scan
      depth - The maximum number of directory levels to search.
      A value of 1 means the search is limited to the jars directly under the searched folder.
      To set no limit, you should set the depth to Integer.MAX_VALUE
      matcher - A matcher to filter the files. IS_JAR can be used to retain all jar files.
      Returns:
      A list of path that matches the matcher
      Throws:
      IOException - if a problem occurs while browsing the folder.
      IllegalArgumentException - if depth is < 1
    • getJarFiles

      public static List<Path> getJarFiles(Path folder, int depth) throws IOException
      Gets the paths of jar files contained in a folder.
      Parameters:
      folder - The folder to scan
      depth - The maximum number of directory levels to search.
      A value of 1 means the search is limited to the jars directly under the searched folder.
      To set no limit, you should set the depth to Integer.MAX_VALUE
      Returns:
      A list of jar files
      Throws:
      IOException - if a problem occurs while browsing the folder.
      IllegalArgumentException - if depth is < 1
      See Also: