Class FSUtil

java.lang.Object
org.apache.tika.batch.fs.FSUtil

public class FSUtil extends Object
Utility class to handle some common issues when reading from and writing to a file system (FS).
  • Constructor Details

    • FSUtil

      public FSUtil()
  • Method Details

    • checkThisIsAncestorOfThat

      @Deprecated public static boolean checkThisIsAncestorOfThat(File ancestor, File child)
      Deprecated.
    • checkThisIsAncestorOfOrSameAsThat

      @Deprecated public static boolean checkThisIsAncestorOfOrSameAsThat(File ancestor, File child)
      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 output
      initialRelativePath - initial relative path (including file name, which may be renamed)
      handleExisting - what to do if the output file exists
      suffix - 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 path
      initialRelativePath - relative path including file ("somedir/subdir1/file.doc")
      handleExisting - policy for what to do if the output path already exists
      suffix - suffix to add to the output path
      Returns:
      can return null
      Throws:
      IOException
    • resolveRelative

      public static Path resolveRelative(Path p, String other)
      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