Package org.apache.tika.batch.fs
Class FSUtil
java.lang.Object
org.apache.tika.batch.fs.FSUtil
Utility class to handle some common issues when
reading from and writing to a file system (FS).
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckThisIsAncestorOfOrSameAsThat(File ancestor, File child) Deprecated.static booleancheckThisIsAncestorOfThat(File ancestor, File child) Deprecated.static FilegetOutputFile(File outputRoot, String initialRelativePath, FSUtil.HANDLE_EXISTING handleExisting, String suffix) Deprecated.static PathgetOutputPath(Path outputRoot, String initialRelativePath, FSUtil.HANDLE_EXISTING handleExisting, String suffix) Given an output root and an initial relative path, return the output file according to the HANDLE_EXISTING strategystatic PathresolveRelative(Path p, String other) Convenience method to ensure that "other" is not an absolute path.
-
Constructor Details
-
FSUtil
public FSUtil()
-
-
Method Details
-
checkThisIsAncestorOfThat
Deprecated. -
checkThisIsAncestorOfOrSameAsThat
Deprecated. -
getOutputFile
@Deprecated public static File getOutputFile(File outputRoot, String initialRelativePath, FSUtil.HANDLE_EXISTING handleExisting, String suffix) throws IOException Deprecated.Given an output root and an initial relative path, return the output file according to the HANDLE_EXISTING strategy In the most basic use case, given a root directory "input", a file's relative path "dir1/dir2/fileA.docx", and an output directory "output", the output file would be "output/dir1/dir2/fileA.docx." If HANDLE_EXISTING is set to OVERWRITE, this will not check to see if the output already exists, and the returned file could overwrite an existing file!!! If HANDLE_EXISTING is set to RENAME, this will try to increment a counter at the end of the file name (fileA(2).docx) until there is a file name that doesn't exist. This will return null if handleExisting == HANDLE_EXISTING.SKIP and the candidate file already exists. This will throw an IOException if HANDLE_EXISTING is set to RENAME, and a candidate cannot output file cannot be found after trying to increment the file count (e.g. fileA(2).docx) 10000 times and then after trying 20,000 UUIDs.- Parameters:
outputRoot- directory root for outputinitialRelativePath- initial relative path (including file name, which may be renamed)handleExisting- what to do if the output file existssuffix- suffix to add to files, can be null- Returns:
- output file or null if no output file should be created
- Throws:
IOException- See Also:
-
getOutputPath
public static Path getOutputPath(Path outputRoot, String initialRelativePath, FSUtil.HANDLE_EXISTING handleExisting, String suffix) throws IOException Given an output root and an initial relative path, return the output file according to the HANDLE_EXISTING strategy In the most basic use case, given a root directory "input", a file's relative path "dir1/dir2/fileA.docx", and an output directory "output", the output file would be "output/dir1/dir2/fileA.docx." If HANDLE_EXISTING is set to OVERWRITE, this will not check to see if the output already exists, and the returned file could overwrite an existing file!!! If HANDLE_EXISTING is set to RENAME, this will try to increment a counter at the end of the file name (fileA(2).docx) until there is a file name that doesn't exist. This will return null if handleExisting == HANDLE_EXISTING.SKIP and the candidate file already exists. This will throw an IOException if HANDLE_EXISTING is set to RENAME, and a candidate cannot output file cannot be found after trying to increment the file count (e.g. fileA(2).docx) 10000 times and then after trying 20,000 UUIDs.- Parameters:
outputRoot- root directory into which to put the pathinitialRelativePath- relative path including file ("somedir/subdir1/file.doc")handleExisting- policy for what to do if the output path already existssuffix- suffix to add to the output path- Returns:
- can return null
- Throws:
IOException
-
resolveRelative
Convenience method to ensure that "other" is not an absolute path. One could imagine malicious use of this.- Parameters:
p-other-- Returns:
- resolved path
- Throws:
IllegalArgumentException- if "other" is an absolute path
-