Class FileUtil

java.lang.Object
ai.attackframework.tools.burp.utils.FileUtil

public final class FileUtil extends Object
Small file utilities used by the UI and sinks. Keeps I/O concerns out of UI code.
  • Method Details

    • ensureJsonFiles

      public static List<FileUtil.CreateResult> ensureJsonFiles(String rootDir, List<String> fileNames)
      Convenience overload that keeps UI code free of Path construction.
      Parameters:
      rootDir - root directory string
      fileNames - file names to ensure
      Returns:
      results per file
    • ensureJsonFiles

      public static List<FileUtil.CreateResult> ensureJsonFiles(Path rootDir, List<String> fileNames)
      Ensures JSON files exist under rootDir.

      Parent directories are created as needed. Each result reports FileUtil.Status.CREATED, FileUtil.Status.EXISTS, or FileUtil.Status.FAILED.

      Parameters:
      rootDir - base directory
      fileNames - file names to create
      Returns:
      creation results
    • ensureFiles

      public static List<FileUtil.CreateResult> ensureFiles(Path rootDir, List<String> fileNames)
      Ensure a set of files exist under rootDir. Creates parent dirs as needed. For each file, returns CREATED, EXISTS, or FAILED with error message.
      Parameters:
      rootDir - base directory
      fileNames - file names to create
      Returns:
      creation results
    • ensureDirectoryWritable

      public static void ensureDirectoryWritable(Path rootDir, String context) throws IOException
      Ensures a directory is creatable and writable by performing a tiny probe write.

      This is used before user-visible file export work so the UI can fail fast with a clean status instead of starting export and discovering write failures later.

      Parameters:
      rootDir - directory that should accept exporter-managed writes
      context - short user/log context for low-disk errors
      Throws:
      IOException - when the directory cannot be created or written
    • requireAbsoluteDirectoryPath

      public static Path requireAbsoluteDirectoryPath(String rootDir) throws IOException
      Parses and validates a file-export root entered in the UI.

      The exporter expects an absolute directory path so operators always know exactly where files are being written. Relative paths are rejected instead of being resolved against the host process working directory.

      Parameters:
      rootDir - raw UI path string
      Returns:
      normalized absolute path
      Throws:
      IOException - when the path is blank, invalid, or not absolute
    • ensureJsonExtension

      public static File ensureJsonExtension(File f)
      Ensures a .json extension on the provided file name.
      Parameters:
      f - file to normalize
      Returns:
      file with .json suffix ensured
    • writeStringCreateDirs

      public static void writeStringCreateDirs(Path file, String content) throws IOException
      Write UTF-8 text to a file, creating parent directories if necessary.

      Caller may invoke from any thread. Before writing, this method applies the shared low-disk guard so exporter code does not keep writing until the destination volume is nearly full.

      Parameters:
      file - destination path
      content - content to write
      Throws:
      IOException - when writing fails
    • readString

      public static String readString(Path file) throws IOException
      Read UTF-8 text from a file.
      Parameters:
      file - file to read
      Returns:
      file contents as string
      Throws:
      IOException - when reading fails
    • writeTempFile

      public static Path writeTempFile(String prefix, String suffix, String content) throws IOException
      Create a temp file and write UTF-8 content to it.

      The file is created under ManagedDiskPaths.managedRootDirectory() so exporter-managed temporary files remain grouped under one discoverable root. This method also applies the shared low-disk guard before creating the file.

      Parameters:
      prefix - temp file prefix
      suffix - temp file suffix
      content - content to write
      Returns:
      path to created temp file
      Throws:
      IOException - when creation or write fails