Class FileUtil

java.lang.Object
org.mpi_sws.jmc.util.FileUtil

public class FileUtil extends Object
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 Details

    • FileUtil

      public FileUtil()
  • Method Details

    • unsafeStoreToFile

      public static void unsafeStoreToFile(String path, String content)
      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 file
      content - the content to store in the file
    • unsafeCreateFile

      public static FileOutputStream unsafeCreateFile(String path)
      Creates a new file at the specified path, deleting it if it already exists.

      This method returns a FileOutputStream for the created file.

      Parameters:
      path - the path to create the file at
      Returns:
      a FileOutputStream for the created file, or null if an error occurs
    • unsafeEnsurePath

      public static void unsafeEnsurePath(String path)
      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 SchedulingChoice objects into a JSON array and writes it to the specified file path.

      Parameters:
      filePath - the path to the file where the schedule will be stored
      taskSchedule - 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 SchedulingChoice objects 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