Package organizers

Class FileHandler

java.lang.Object
organizers.FileHandler

public class FileHandler extends Object
The FileHandler class is responsible for handling file operations in the Pacman project. It provides methods for initializing directories, cleaning directories, and managing file paths.
  • Field Details

    • cleanDirectories

      public static final boolean cleanDirectories
      Indicates whether the user wants to clean directories. Default: false.

      When cleanDirectories is set to true, the maps directory and logs directory are cleaned, removing all files except sample.map, log_history.csv, and log_errorHistory.csv.

      If cleanDirectories is set to false, subdirectories (actual_logs and previous_logs) are created in the logs directory to store the current and previous log and CSV files, respectively. Similarly, subdirectories (actual_maps and previous_maps) are created in the maps directory to store the current and previous map files, respectively.

    • logHistory

      public static final boolean logHistory
      Indicates whether log history files are generated. Default: true.

      If logHistory is set to true, log_history.csv and log_errorHistory.csv are generated in the main logs directory. These files provide detailed information about the history of previous runs, including timestamps, execution times, exit code counts, and error code and output message combinations.

    • mapsDirectoryPath

      public static final String mapsDirectoryPath
      The path to the overall directory where the map files are located. Path of the system project root + mapsFilePath=maps default config Default: ${project.root}/fuzzresults/maps
    • actualMapsDirectoryPath

      public static final String actualMapsDirectoryPath
      The path to the directory where the actual log files (of this Fuzzer run) are stored. Default: ${project.root}/fuzzresults/maps/actual_maps/
    • previousMapsDirectoryPath

      public static final String previousMapsDirectoryPath
      The path to the directory where the previous log files are stored. These were already there before Fuzz started to run, whether that be in actual_maps or previous_maps. Default: ${project.root}/fuzzresults/maps/previous_maps/
    • logsDirectoryPath

      public static final String logsDirectoryPath
      The path to the overall directory where the log files are located. Path of the system project root + logFilePath=logs default config Default: ${project.root}/fuzzresults/logs
    • overviewLogsDirectoryPath

      public static final String overviewLogsDirectoryPath
      The path to the directory where the overview log files are stored. Default: ${project.root}/fuzzresults/logs/overview_logs/
    • actualLogsDirectoryPath

      public static final String actualLogsDirectoryPath
      The path to the directory where the actual (of this Fuzzer run) log files are stored. Default: ${project.root}/fuzzresults/logs/actual_logs/
    • previousLogsDirectoryPath

      public static final String previousLogsDirectoryPath
      The path to the directory where the previous log files are stored. These were already there before Fuzz started to run, whether that be in actual_logs or previous_logs. Default: ${project.root}/fuzzresults/logs/previous_logs/
    • logFileName

      public static final String logFileName
      The name of the log file, not the full path! Only the "log.txt" part. Default: log.txt
    • logFilePath

      public static final String logFilePath
      The path to the log.txt file. Default: ${project.root}/fuzzresults/logs/actual_logs/log.txt
    • logCSVFileName

      public static final String logCSVFileName
      The name of the log file, not the full path! Only the "log.csv" part. Default: log.csv
    • logFileCSVPath

      public static final String logFileCSVPath
      The path to the log.csv file. Default: ${project.root}/fuzzresults/logs/actual_logs/log.csv
    • csvFilePath

      public static final String csvFilePath
      The path to the log_overview.csv file. Default: ${project.root}/fuzzresults/logs/actual_logs/log_overview.csv
    • logErrorHistoryFilePath

      public static final String logErrorHistoryFilePath
      The path to the log_errorHistory.csv file. Default: ${project.root}/fuzzresults/logs/log_errorHistory.csv
    • logFullHistoryFilePath

      public static final String logFullHistoryFilePath
      The path to the log_fullHistory.csv file. Default: ${project.root}/fuzzresults/logs/log_fullHistory.csv
    • logHistoryFilePath

      public static final String logHistoryFilePath
      The path to the log_history.csv file. Default: ${project.root}/fuzzresults/logs/log_history.csv
    • logFullHistoryHTMLDirectoryPath

      public static String logFullHistoryHTMLDirectoryPath
      The path to the log_fullHistory_html subdirectory. Default: ${project.root}/fuzzresults/logs/overview_logs/log_fullHistory_html/
    • logFullHistoryHTMLHomeFilePath

      public static String logFullHistoryHTMLHomeFilePath
      The path to the index.html file in the log_fullHistory_html subdirectory. Default: ${project.root}/fuzzresults/logs/overview_logs/log_fullHistory_html/index.html
    • logFullHistoryHTMLAboutTheFuzzerFilePath

      public static String logFullHistoryHTMLAboutTheFuzzerFilePath
      The path to the aboutTheFuzzer.html file in the log_fullHistory_html subdirectory. Default: ${project.root}/fuzzresults/logs/overview_logs/log_fullHistory_html/aboutTheFuzzer.html
    • logFullHistoryHTMLReportAndFuzzLessonsFilePath

      public static String logFullHistoryHTMLReportAndFuzzLessonsFilePath
      The path to the reportAndFuzzLessons.html file in the log_fullHistory_html subdirectory. Default: ${project.root}/fuzzresults/logs/overview_logs/log_fullHistory_html/reportAndFuzzLessons.html
    • logFullHistoryHTMLAllMapsFilePath

      public static String logFullHistoryHTMLAllMapsFilePath
      The path to the allMaps.html file in the log_fullHistory_html subdirectory. Default: ${project.root}/fuzzresults/logs/overview_logs/log_fullHistory_html/allMaps.html
    • logFullHistoryHTMLWelcomeFilePath

      public static String logFullHistoryHTMLWelcomeFilePath
      The path to the welcome.html file in the log_fullHistory_html subdirectory.
    • fuzzAttemptNr

      public static int fuzzAttemptNr
      Count the amount of times the fuzzer has run.

      We could also just count in fuzz class -> would not take into account cleanDirectories and the user deleting * any fuzz-result directory. * We could also just count the highest subDirectory of previous -> would not take into account the user deleting the * actual_maps of his latest run or the user deleting any previous_ directories. We want the count to be accurate when deleting * runs (e.g. deleting run_3 should still give us run_4 and not a new run_3). This is because otherwise the log files * would have the wrong number in their overview files, since the lines of the deleted run_3 will still be in the log files.

  • Constructor Details

    • FileHandler

      public FileHandler()
  • Method Details

    • initializeDirectories

      public void initializeDirectories()
      Updates the fuzzAttemptNr with the correct number in its text file. Initializes the necessary directories for file handling. Creates the overall result, logs, and maps directories. Moves existing files and directories from the actual_logs and actual_maps directories to the previous_logs and previous_maps directories, respectively, based on the clean-up rules.
    • getFileName

      public static String getFileName(String filePath)
      Get the name of the map file on this path
      Parameters:
      filePath - Relative filepath
      Returns:
      String filename of the map.
    • getFileText

      public static String getFileText(String filePath)
      Gives the full text of the text file
      Parameters:
      filePath - Relative filepath to project, without extension.
      Returns:
      String full text of file
    • normalizeFilePath

      public static String normalizeFilePath(String filePath, boolean backlash, boolean relative)
      Returns a clean-up file path as string, taking into account different uses of / and \ and if the path should be relative
      Parameters:
      filePath - String filePath that needs to be cleaned up
      backlash - boolean if backslash should be used instead of forward slash
      relative - boolean if the path should be relative
      Returns:
      String file path that only has single \ or / in it
    • normalizeFilePath

      public static String normalizeFilePath(String filePath)
      Default values of normalizeFilePath are forward slash and absolute path
      Parameters:
      filePath - String absolute file path
      Returns:
      filePath String absolute file path with /
    • normalizeFilePath

      public static Path normalizeFilePath(String filePath, boolean backlash)
      Returns a cleaned-up file path as Path object, taking into account different uses of / and \
      Parameters:
      filePath - String absolute file path
      backlash - boolean if backslash should be used instead of forward slash
      Returns:
      filePath Path object
    • normalizeFilePath

      public static Path normalizeFilePath(Path filePath, boolean backlash)
      Returns a cleaned-up file path as Path object, taking into account different uses of / and \
      Parameters:
      filePath - Path object
      backlash - if backslash should be used instead of forward slash
      Returns:
      filePath Path object