fmpp.util
Class FileUtil

java.lang.Object
  extended by fmpp.util.FileUtil

public class FileUtil
extends java.lang.Object

Collection of file and path related functions.


Constructor Summary
FileUtil()
           
 
Method Summary
static java.lang.String compressPath(java.lang.String path, int maxPathLength)
          Returns a compressed version of the path.
static void copyFile(java.io.File src, java.io.File dst)
          Same as copyFile(src, dst, true)).
static void copyFile(java.io.File src, java.io.File dst, boolean copyLMD)
          Copies a file; silently overwrites the destination if already exists.
static java.lang.String getRelativePath(java.io.File fromDir, java.io.File toFileOrDir)
          Reaturns the path of a file or directory relative to a directory, in native format.
static boolean isInside(java.io.File file, java.io.File ascendant)
          Returns true if file is inside ascendant, otherwise returns false.
static boolean isInsideOrEquals(java.io.File file, java.io.File ascendant)
          Returns true if file is inside ascendant or file is the same as the ascendant, otherwise returns false.
static byte[] loadByteArray(java.io.InputStream in)
           
static java.lang.String loadString(java.io.InputStream in, java.lang.String charset)
           
static java.lang.String pathPatternToPerl5Regex(java.lang.String text)
          Convers UN*X style path to Perl 5 regular expression.
static java.lang.String pathToUnixStyle(java.lang.String path)
          Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions.
static java.lang.String removeSlashPrefix(java.lang.String path)
           
static java.io.File resolveRelativeUnixPath(java.io.File root, java.io.File wd, java.lang.String path)
          Resolves relative UN*X path based on given root and working directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

getRelativePath

public static java.lang.String getRelativePath(java.io.File fromDir,
                                               java.io.File toFileOrDir)
                                        throws java.io.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:
java.io.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(java.io.File src,
                            java.io.File dst,
                            boolean copyLMD)
                     throws java.io.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:
java.io.IOException

copyFile

public static void copyFile(java.io.File src,
                            java.io.File dst)
                     throws java.io.IOException
Same as copyFile(src, dst, true)).

Throws:
java.io.IOException

isInsideOrEquals

public static boolean isInsideOrEquals(java.io.File file,
                                       java.io.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(java.io.File file,
                               java.io.File ascendant)
Returns true if file is inside ascendant, otherwise returns false.


resolveRelativeUnixPath

public static java.io.File resolveRelativeUnixPath(java.io.File root,
                                                   java.io.File wd,
                                                   java.lang.String path)
                                            throws java.io.IOException
Resolves relative UN*X path based on given root and working directory.

Parameters:
root - root directory
wd - working directory (current direcory)
Throws:
java.io.IOException

compressPath

public static java.lang.String compressPath(java.lang.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 java.lang.String pathToUnixStyle(java.lang.String path)
Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions.


removeSlashPrefix

public static java.lang.String removeSlashPrefix(java.lang.String path)

pathPatternToPerl5Regex

public static java.lang.String pathPatternToPerl5Regex(java.lang.String text)
Convers UN*X style path to Perl 5 regular expression. In additional to standard UN*X path meta characters (*, ?) it understands **, that is the same as in Jakarta Ant. It assumes that the paths what you will later match with the pattern are always starting with slash (they are absoulte paths to an imaginary base).


loadString

public static java.lang.String loadString(java.io.InputStream in,
                                          java.lang.String charset)
                                   throws java.io.IOException
Throws:
java.io.IOException

loadByteArray

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