Package org.carrot2.util
Class FileUtils
java.lang.Object
org.carrot2.util.FileUtils
Various utility methods for working with
File
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic String
canonicalize
(String path, String separator) Removes useless segments in relative paths, e.g.static String
changeRoot
(String file, String oldRoot, String newRoot) Changes the root directory of a file.static void
deleteThrowingExceptions
(File... files) Attempts to delete the provided files and throws anIOException
in caseFile.delete()
returnsfalse
for any of them.static File
Creates a newFile
from the provided path and attempts to executeFile.getCanonicalFile()
.static boolean
isFileInParent
(File file, File parent) Returnstrue
if file is contained in the parent directory or any parent of the parent directory.static void
mkdirsThrowingExceptions
(File dirs)
-
Method Details
-
getCanonicalOrAbsoluteFile
Creates a newFile
from the provided path and attempts to executeFile.getCanonicalFile()
. In case of a failure, returns the result ofFile.getAbsoluteFile()
.- Parameters:
path
- the path- Returns:
- the canonical or absolute file
-
changeRoot
Changes the root directory of a file. For example, file is /a/b/c/d/e and oldRoot is /a/b/c, and newRoot is /x/y, the result will be /x/y/d/e.- Parameters:
file
- the fileoldRoot
- the old rootnewRoot
- the new root- Returns:
- the string
-
canonicalize
Removes useless segments in relative paths, e.g. replaces../path/../other/file.css
with../other/file.css
- Parameters:
path
- the pathseparator
- the separator- Returns:
- the string
-
deleteThrowingExceptions
Attempts to delete the provided files and throws anIOException
in caseFile.delete()
returnsfalse
for any of them.- Parameters:
files
- the files- Throws:
IOException
- Signals that an I/O exception has occurred.
-
mkdirsThrowingExceptions
- Parameters:
dirs
- the dirs- Throws:
IOException
- Signals that an I/O exception has occurred.
-
isFileInParent
Returnstrue
if file is contained in the parent directory or any parent of the parent directory.- Parameters:
file
- the fileparent
- the parent- Returns:
- true, if is file in parent
-