Package com.fathzer.plugin.loader.utils
Class FileUtils
java.lang.Object
com.fathzer.plugin.loader.utils.FileUtils
Some utilities about files.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BiPredicate<Path,BasicFileAttributes> A predicate that matches jar files. -
Method Summary
Modifier and TypeMethodDescriptiongetFiles(Path folder, int depth, BiPredicate<Path, BasicFileAttributes> matcher) Gets the paths of files contained in a folder.getJarFiles(Path folder, int depth) Gets the paths of jar files contained in a folder.static URLGets 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.
-
Field Details
-
IS_JAR
A predicate that matches jar files.- See Also:
-
-
Method Details
-
getURL
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 IOExceptionGets the paths of files contained in a folder.- Parameters:
folder- The folder to scandepth- 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_VALUEmatcher- A matcher to filter the files.IS_JARcan 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
Gets the paths of jar files contained in a folder.- Parameters:
folder- The folder to scandepth- 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:
-