Package org.pf4j.util
Class FileUtils
- java.lang.Object
-
- org.pf4j.util.FileUtils
-
public class FileUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voiddelete(java.nio.file.Path path)Delete a file or recursively delete a folder, do not follow symlinks.static java.nio.file.PathexpandIfZip(java.nio.file.Path filePath)Unzip a zip file in a directory that has the same name as the zip file.static java.nio.file.PathfindFile(java.nio.file.Path directoryPath, java.lang.String fileName)static java.nio.file.PathfindWithEnding(java.nio.file.Path basePath, java.lang.String... endings)Finds a path with various endings or null if not found.private static java.nio.file.FileSystemgetFileSystem(java.net.URI uri)static java.util.List<java.io.File>getJars(java.nio.file.Path folder)private static voidgetJars(java.util.List<java.io.File> bucket, java.nio.file.Path folder)static java.nio.file.PathgetPath(java.net.URI uri, java.lang.String first, java.lang.String... more)static java.nio.file.PathgetPath(java.nio.file.Path path, java.lang.String first, java.lang.String... more)static booleanisJarFile(java.nio.file.Path path)Return true only if path is a jar file.static booleanisZipFile(java.nio.file.Path path)Return true only if path is a zip file.static voidoptimisticDelete(java.nio.file.Path path)Delete a file (not recursively) and ignore any errors.static java.util.List<java.lang.String>readLines(java.nio.file.Path path, boolean ignoreComments)static voidwriteLines(java.util.Collection<java.lang.String> lines, java.io.File file)Deprecated.static voidwriteLines(java.util.Collection<java.lang.String> lines, java.nio.file.Path path)
-
-
-
Method Detail
-
readLines
public static java.util.List<java.lang.String> readLines(java.nio.file.Path path, boolean ignoreComments) throws java.io.IOException- Throws:
java.io.IOException
-
writeLines
@Deprecated public static void writeLines(java.util.Collection<java.lang.String> lines, java.io.File file) throws java.io.IOExceptionDeprecated.UsewriteLines(Collection, Path)instead.- Throws:
java.io.IOException
-
writeLines
public static void writeLines(java.util.Collection<java.lang.String> lines, java.nio.file.Path path) throws java.io.IOException- Throws:
java.io.IOException
-
delete
public static void delete(java.nio.file.Path path) throws java.io.IOExceptionDelete a file or recursively delete a folder, do not follow symlinks.- Parameters:
path- the file or folder to delete- Throws:
java.io.IOException- if something goes wrong
-
getJars
public static java.util.List<java.io.File> getJars(java.nio.file.Path folder)
-
getJars
private static void getJars(java.util.List<java.io.File> bucket, java.nio.file.Path folder)
-
findWithEnding
public static java.nio.file.Path findWithEnding(java.nio.file.Path basePath, java.lang.String... endings)Finds a path with various endings or null if not found.- Parameters:
basePath- the base nameendings- a list of endings to search for- Returns:
- new path or null if not found
-
optimisticDelete
public static void optimisticDelete(java.nio.file.Path path)
Delete a file (not recursively) and ignore any errors.- Parameters:
path- the path to delete
-
expandIfZip
public static java.nio.file.Path expandIfZip(java.nio.file.Path filePath) throws java.io.IOExceptionUnzip a zip file in a directory that has the same name as the zip file. For example if the zip file ismy-plugin.zipthen the resulted directory ismy-plugin.- Parameters:
filePath- the file to evaluate- Returns:
- Path of unzipped folder or original path if this was not a zip file
- Throws:
java.io.IOException- on error
-
isZipFile
public static boolean isZipFile(java.nio.file.Path path)
Return true only if path is a zip file.- Parameters:
path- to a file/dir- Returns:
- true if file with
.zipending
-
isJarFile
public static boolean isJarFile(java.nio.file.Path path)
Return true only if path is a jar file.- Parameters:
path- to a file/dir- Returns:
- true if file with
.jarending
-
getPath
public static java.nio.file.Path getPath(java.nio.file.Path path, java.lang.String first, java.lang.String... more) throws java.io.IOException- Throws:
java.io.IOException
-
getPath
public static java.nio.file.Path getPath(java.net.URI uri, java.lang.String first, java.lang.String... more) throws java.io.IOException- Throws:
java.io.IOException
-
findFile
public static java.nio.file.Path findFile(java.nio.file.Path directoryPath, java.lang.String fileName)
-
getFileSystem
private static java.nio.file.FileSystem getFileSystem(java.net.URI uri) throws java.io.IOException- Throws:
java.io.IOException
-
-