Class FileUtil
java.lang.Object
ai.attackframework.tools.burp.utils.FileUtil
Small file utilities used by the UI and sinks. Keeps I/O concerns out of UI code.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOutcome of ensuring a JSON file exists.static enumStatus of file creation attempts. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidensureDirectoryWritable(Path rootDir, String context) Ensures a directory is creatable and writable by performing a tiny probe write.static FileEnsure a.jsonextension on the provided file name (case-insensitive).static List<FileUtil.CreateResult> ensureJsonFiles(String rootDir, List<String> fileNames) Convenience overload to keep panel code free of Path construction.static List<FileUtil.CreateResult> ensureJsonFiles(Path rootDir, List<String> fileNames) Ensure a set of JSON files exist underrootDir.static StringreadString(Path file) Read UTF-8 text from a file.static voidwriteStringCreateDirs(Path file, String content) Write UTF-8 text to a file, creating parent directories if necessary.static PathwriteTempFile(String prefix, String suffix, String content) Create a temp file and write UTF-8 content to it.
-
Method Details
-
ensureJsonFiles
Convenience overload to keep panel code free of Path construction. Delegates to the Path-based variant.- Parameters:
rootDir- root directory stringfileNames- file names to ensure- Returns:
- results per file
-
ensureJsonFiles
Ensure a set of JSON files exist underrootDir. Creates parent dirs as needed. For each file, returns CREATED, EXISTS, or FAILED with error message.- Parameters:
rootDir- base directoryfileNames- file names to create- Returns:
- creation results
-
ensureDirectoryWritable
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 writescontext- short user/log context for low-disk errors- Throws:
IOException- when the directory cannot be created or written
-
ensureJsonExtension
Ensure a.jsonextension on the provided file name (case-insensitive).- Parameters:
f- file to normalize- Returns:
- file with .json suffix ensured
-
writeStringCreateDirs
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 pathcontent- content to write- Throws:
IOException- when writing fails
-
readString
Read UTF-8 text from a file.- Parameters:
file- file to read- Returns:
- file contents as string
- Throws:
IOException- when reading fails
-
writeTempFile
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 prefixsuffix- temp file suffixcontent- content to write- Returns:
- path to created temp file
- Throws:
IOException- when creation or write fails
-