Package org.mpi_sws.jmc.util
Class FileUtil
java.lang.Object
org.mpi_sws.jmc.util.FileUtil
Utility class for file operations related to storing and reading task schedules.
This class provides methods to store task schedules to a file and read them back, as well as utility methods for file and path operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<SchedulingChoice<?>> readTaskSchedule(String filePath) Reads a task schedule from a JSON file.static voidstoreTaskSchedule(String filePath, List<? extends SchedulingChoice<?>> taskSchedule) Stores the task schedule to a file in JSON format.static FileOutputStreamunsafeCreateFile(String path) Creates a new file at the specified path, deleting it if it already exists.static voidunsafeEnsurePath(String path) Ensure the path exists, creating it if it does not.static voidunsafeStoreToFile(String path, String content) Stores the given content to a file at the specified path.
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
unsafeStoreToFile
Stores the given content to a file at the specified path.This method overwrites the file if it already exists and silently ignores any IOExceptions that may occur during the operation.
- Parameters:
path- the path to the filecontent- the content to store in the file
-
unsafeCreateFile
Creates a new file at the specified path, deleting it if it already exists.This method returns a
FileOutputStreamfor the created file.- Parameters:
path- the path to create the file at- Returns:
- a
FileOutputStreamfor the created file, or null if an error occurs
-
unsafeEnsurePath
Ensure the path exists, creating it if it does not.Deletes the contents of the path if it already exists.
- Parameters:
path- the path to ensure
-
storeTaskSchedule
public static void storeTaskSchedule(String filePath, List<? extends SchedulingChoice<?>> taskSchedule) throws JmcCheckerException Stores the task schedule to a file in JSON format.This method serializes the list of
SchedulingChoiceobjects into a JSON array and writes it to the specified file path.- Parameters:
filePath- the path to the file where the schedule will be storedtaskSchedule- the list of scheduling choices to store- Throws:
JmcCheckerException- if an error occurs while writing to the file
-
readTaskSchedule
public static List<SchedulingChoice<?>> readTaskSchedule(String filePath) throws JmcCheckerException Reads a task schedule from a JSON file.This method reads the content of the specified file, parses it as JSON, and constructs a list of
SchedulingChoiceobjects based on the parsed data.- Parameters:
filePath- the path to the file containing the task schedule- Returns:
- a list of scheduling choices read from the file
- Throws:
JmcCheckerException- if an error occurs while reading or parsing the file
-