Class FileUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDescribes the outcome 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 List<FileUtil.CreateResult> ensureFiles(Path rootDir, List<String> fileNames) Ensure a set of files exist underrootDir.static FileEnsures a.jsonextension on the provided file name.static List<FileUtil.CreateResult> ensureJsonFiles(String rootDir, List<String> fileNames) Convenience overload that keeps UI code free ofPathconstruction.static List<FileUtil.CreateResult> ensureJsonFiles(Path rootDir, List<String> fileNames) Ensures JSON files exist underrootDir.static StringreadString(Path file) Read UTF-8 text from a file.static PathrequireAbsoluteDirectoryPath(String rootDir) Parses and validates a file-export root entered in the UI.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 that keeps UI code free ofPathconstruction.- Parameters:
rootDir- root directory stringfileNames- file names to ensure- Returns:
- results per file
-
ensureJsonFiles
Ensures JSON files exist underrootDir.Parent directories are created as needed. Each result reports
FileUtil.Status.CREATED,FileUtil.Status.EXISTS, orFileUtil.Status.FAILED.- Parameters:
rootDir- base directoryfileNames- file names to create- Returns:
- creation results
-
ensureFiles
Ensure a set of 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
-
requireAbsoluteDirectoryPath
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
Ensures a.jsonextension on the provided file name.- 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
-