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 to keep panel code free of Path construction. Delegates to the Path-based variant.

      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)
      Ensure a set of JSON 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
    • ensureJsonExtension

      public static File ensureJsonExtension(File f)
      Ensure a .json extension on the provided file name (case-insensitive).

      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