Class FilteringUtils


  • public final class FilteringUtils
    extends Object
    Author:
    Olivier Lamy, Dennis Lundberg
    • Method Detail

      • escapeWindowsPath

        public static String escapeWindowsPath​(String val)
        Parameters:
        val - The value to be escaped.
        Returns:
        Escaped value
      • resolveFile

        public static File resolveFile​(File baseFile,
                                       String filename)
        Resolve a file filename to its canonical form. If filename is relative (doesn't start with /), it is resolved relative to baseFile. Otherwise it is treated as a normal root-relative path.
        Parameters:
        baseFile - where to resolve filename from, if filename is relative
        filename - absolute or relative file path to resolve
        Returns:
        the canonical File of filename
      • getRelativeFilePath

        public static String getRelativeFilePath​(String oldPath,
                                                 String newPath)

        This method can calculate the relative path between two paths on a file system.

         PathTool.getRelativeFilePath( null, null )                                   = ""
         PathTool.getRelativeFilePath( null, "/usr/local/java/bin" )                  = ""
         PathTool.getRelativeFilePath( "/usr/local", null )                           = ""
         PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" )          = "java/bin"
         PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" )         = "java/bin"
         PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" )         = "../.."
         PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) = "java/bin/java.sh"
         PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) = "../../.."
         PathTool.getRelativeFilePath( "/usr/local/", "/bin" )                        = "../../bin"
         PathTool.getRelativeFilePath( "/bin", "/usr/local/" )                        = "../usr/local"
         
        Note: On Windows based system, the / character should be replaced by \ character.
        Parameters:
        oldPath - old path
        newPath - new path
        Returns:
        a relative file path from oldPath.
      • copyFile

        public static void copyFile​(File from,
                                    File to,
                                    String encoding,
                                    FilterWrapper[] wrappers)
                             throws IOException
        If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true.
        Parameters:
        from - the file to copy
        to - the destination file
        encoding - the file output encoding (only if wrappers is not empty)
        wrappers - array of FilterWrapper
        Throws:
        IOException - if an IO error occurs during copying or filtering
      • copyFile

        @Deprecated
        public static void copyFile​(File from,
                                    File to,
                                    String encoding,
                                    FilterWrapper[] wrappers,
                                    boolean overwrite)
                             throws IOException
        If wrappers is null or empty, the file will be copy only if to.lastModified() < from.lastModified() or if overwrite is true.
        Parameters:
        from - the file to copy
        to - the destination file
        encoding - the file output encoding (only if wrappers is not empty)
        wrappers - array of FilterWrapper
        overwrite - unused
        Throws:
        IOException - if an IO error occurs during copying or filtering