Package org.pf4j.util

Class FileUtils


  • public class FileUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger log  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void delete​(java.nio.file.Path path)
      Delete a file or recursively delete a folder, do not follow symlinks.
      static java.nio.file.Path expandIfZip​(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.Path findFile​(java.nio.file.Path directoryPath, java.lang.String fileName)  
      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.
      private static java.nio.file.FileSystem getFileSystem​(java.net.URI uri)  
      static java.util.List<java.io.File> getJars​(java.nio.file.Path folder)  
      private static void getJars​(java.util.List<java.io.File> bucket, java.nio.file.Path folder)  
      static java.nio.file.Path getPath​(java.net.URI uri, java.lang.String first, java.lang.String... more)  
      static java.nio.file.Path getPath​(java.nio.file.Path path, java.lang.String first, java.lang.String... more)  
      static boolean isJarFile​(java.nio.file.Path path)
      Return true only if path is a jar file.
      static boolean isZipFile​(java.nio.file.Path path)
      Return true only if path is a zip file.
      static void optimisticDelete​(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 void writeLines​(java.util.Collection<java.lang.String> lines, java.io.File file)
      Deprecated.
      static void writeLines​(java.util.Collection<java.lang.String> lines, java.nio.file.Path path)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static final org.slf4j.Logger log
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • 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.IOException
        Deprecated.
        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.IOException
        Delete 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 name
        endings - 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.IOException
        Unzip a zip file in a directory that has the same name as the zip file. For example if the zip file is my-plugin.zip then the resulted directory is my-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 .zip ending
      • 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 .jar ending
      • 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