Class FilteringUtils

java.lang.Object
org.apache.maven.shared.filtering.FilteringUtils

public final class FilteringUtils extends Object
  • Field Details

    • ONE_KB

      private static final int ONE_KB
      The number of bytes in a kilobyte.
      See Also:
    • ONE_MB

      private static final int ONE_MB
      The number of bytes in a megabyte.
      See Also:
    • FILE_COPY_BUFFER_SIZE

      private static final int FILE_COPY_BUFFER_SIZE
      The file copy buffer size (30 MB)
      See Also:
    • WINDOWS_PATH_PATTERN

      private static final String WINDOWS_PATH_PATTERN
      See Also:
    • PATTERN

      private static final Pattern PATTERN
    • COPY_BUFFER_LENGTH

      public static final int COPY_BUFFER_LENGTH
      See Also:
  • Constructor Details

    • FilteringUtils

      private FilteringUtils()
  • Method Details

    • 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.
    • buildRelativePath

      private static String buildRelativePath(String toPath, String fromPath, char separatorChar)
    • isEmpty

      static boolean isEmpty(String string)
    • 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
    • copyFilePermissions

      private static void copyFilePermissions(File source, File destination) throws IOException
      Attempts to copy file permissions from the source to the destination file. Initially attempts to copy posix file permissions, assuming that the files are both on posix filesystems. If the initial attempts fail then a second attempt using less precise permissions model. Note that permissions are copied on a best-efforts basis, failure to copy permissions will not result in an exception.
      Parameters:
      source - the file to copy permissions from.
      destination - the file to copy permissions to.
      Throws:
      IOException
    • setReadWritePermissions

      private static void setReadWritePermissions(File file) throws IOException
      Throws:
      IOException
    • charset

      private static Charset charset(String encoding)