Package fmpp.util

Class FileUtil

java.lang.Object
fmpp.util.FileUtil

public class FileUtil extends Object
Collection of file and path related functions.
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • getRelativePath

      public static String getRelativePath(File fromDir, File toFileOrDir) throws IOException
      Reaturns the path of a file or directory relative to a directory, in native format.
      Returns:
      The relative path. It never starts with separator char (/ on UN*X).
      Throws:
      IOException - if the two paths has no common parent directory (such as C:\foo.txt and D:\foo.txt), or the the paths are malformed.
    • copyFile

      public static void copyFile(File src, File dst, boolean copyLMD) throws IOException
      Copies a file; silently overwrites the destination if already exists.
      Parameters:
      copyLMD - tells if the last modification time of the original file will be copied too.
      Throws:
      IOException
    • copyFile

      public static void copyFile(File src, File dst) throws IOException
      Throws:
      IOException
    • isInsideOrEquals

      public static boolean isInsideOrEquals(File file, File ascendant)
      Returns true if file is inside ascendant or file is the same as the ascendant, otherwise returns false.
    • isInside

      public static boolean isInside(File file, File ascendant)
      Returns true if file is inside ascendant, otherwise returns false.
    • resolveRelativeUnixPath

      public static File resolveRelativeUnixPath(File root, File wd, String path) throws IOException
      Resolves relative UN*X path based on given root and working directory.
      Parameters:
      root - root directory
      wd - working directory (current direcory)
      Throws:
      IOException
    • compressPath

      public static String compressPath(String path, int maxPathLength)
      Returns a compressed version of the path. For example, /foo/ba.../baaz.txt instead of /foo/bar/blah/blah/blah/baaz.txt.
      Parameters:
      path - the path to compress. Either native or UNIX format.
      maxPathLength - the maximum length of the result. Must be at least 4.
    • pathToUnixStyle

      public static String pathToUnixStyle(String path)
      Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions.
    • removeSlashPrefix

      public static String removeSlashPrefix(String path)
    • getFileExtension

      public static String getFileExtension(String name)
      Returns the part of the name after the last dot, or if there's no dot, null.
      Parameters:
      name - The file name or path. If null, null is returned.
      Since:
      0.9.16
    • getLowerCaseFileExtension

      public static String getLowerCaseFileExtension(String name)
      Same as getFileExtension(String), but also converts the result to lower case.
      Since:
      0.9.16
    • pathPatternToPerl5Regex

      public static String pathPatternToPerl5Regex(String text)
      Converts UN*X style path to regular expression (originally, for Perl 5 dialect, but also works for Java's dialect). In additional to standard UN*X path meta characters (*, ?) it understands **, that is the same as in Ant. It assumes that the paths what you will later match with the pattern are always starting with slash (they are absolute paths to an imaginary base).
    • loadString

      public static String loadString(InputStream in, String charset) throws IOException
      Throws:
      IOException
    • loadByteArray

      public static byte[] loadByteArray(InputStream in) throws IOException
      Throws:
      IOException