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 String
compressPath
(String path, int maxPathLength) Returns a compressed version of the path.static void
Same ascopyFile(src, dst, true))
.static void
Copies a file; silently overwrites the destination if already exists.static String
getFileExtension
(String name) Returns the part of the name after the last dot, or if there's no dot,null
.static String
Same asgetFileExtension(String)
, but also converts the result to lower case.static String
getRelativePath
(File fromDir, File toFileOrDir) Reaturns the path of a file or directory relative to a directory, in native format.static boolean
Returns true iffile
is insideascendant
, otherwise returns false.static boolean
isInsideOrEquals
(File file, File ascendant) Returns true iffile
is insideascendant
orfile
is the same as theascendant
, otherwise returns false.static byte[]
static String
loadString
(InputStream in, String charset) static String
Converts UN*X style path to regular expression (originally, for Perl 5 dialect, but also works for Java's dialect).static String
pathToUnixStyle
(String path) Brings the path to UNI*X style format, so that it can be handled with path pattern handling functions.static String
removeSlashPrefix
(String path) static File
resolveRelativeUnixPath
(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.txt
andD:\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 iffile
is insideascendant
orfile
is the same as theascendant
, otherwise returns false. -
isInside
Returns true iffile
is 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.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
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
,null
is 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
-