Package fmpp.util
Class FileUtil
java.lang.Object
fmpp.util.FileUtil
Collection of file and path related functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcompressPath(String path, int maxPathLength) Returns a compressed version of the path.static voidSame ascopyFile(src, dst, true)).static voidCopies a file; silently overwrites the destination if already exists.static StringgetFileExtension(String name) Returns the part of the name after the last dot, or if there's no dot,null.static StringSame asgetFileExtension(String), but also converts the result to lower case.static StringgetRelativePath(File fromDir, File toFileOrDir) Reaturns the path of a file or directory relative to a directory, in native format.static booleanReturns true iffileis insideascendant, otherwise returns false.static booleanisInsideOrEquals(File file, File ascendant) Returns true iffileis insideascendantorfileis the same as theascendant, otherwise returns false.static byte[]static StringloadString(InputStream in, String charset) static StringConverts UN*X style path to regular expression (originally, for Perl 5 dialect, but also works for Java's dialect).static StringpathToUnixStyle(String path) Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions.static StringremoveSlashPrefix(String path) static FileresolveRelativeUnixPath(File root, File wd, String path) Resolves relative UN*X path based on given root and working directory.
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
getRelativePath
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 asC:\foo.txtandD:\foo.txt), or the the paths are malformed.
-
copyFile
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
Same ascopyFile(src, dst, true)).- Throws:
IOException
-
isInsideOrEquals
Returns true iffileis insideascendantorfileis the same as theascendant, otherwise returns false. -
isInside
Returns true iffileis insideascendant, otherwise returns false. -
resolveRelativeUnixPath
Resolves relative UN*X path based on given root and working directory.- Parameters:
root- root directorywd- working directory (current direcory)- Throws:
IOException
-
compressPath
Returns a compressed version of the path. For example,/foo/ba.../baaz.txtinstead 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
Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions. -
removeSlashPrefix
-
getFileExtension
Returns the part of the name after the last dot, or if there's no dot,null.- Parameters:
name- The file name or path. Ifnull,nullis returned.- Since:
- 0.9.16
-
getLowerCaseFileExtension
Same asgetFileExtension(String), but also converts the result to lower case.- Since:
- 0.9.16
-
pathPatternToPerl5Regex
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
- Throws:
IOException
-
loadByteArray
- Throws:
IOException
-