Package persistence

Class FileHandler

java.lang.Object
persistence.FileHandler

public class FileHandler extends Object
Implementation of FileHandler class, contains static methods for saving and loading Map and Game state to and from files.
  • Constructor Details

    • FileHandler

      public FileHandler()
  • Method Details

    • saveMap

      public static void saveMap(File file, Map map)
      Saves a Map instance to a specified file.
      Parameters:
      file - the File we want to save to
      map - the Map instance we want to save
    • saveGame

      public static void saveGame(File file, Game game)
      Saves a Game instance to a specified file.
      Parameters:
      file - the File we want to save to
      game - the Game instance we want to save
    • saveToJson

      public static void saveToJson(File file, Object obj, String type)
      The logic of saving an Object state to a specified file with a specified file type.
      Parameters:
      file - the File we want to save to
      obj - the Object we want to save
      type - the extension of the file we save to
    • loadMap

      public static Map loadMap(File file)
      Loads a Map instance from a specified file.
      Parameters:
      file - the file we want to load from
      Returns:
      a Map instance from the specified file
    • loadMapAndFile

      public static Pair<Map,File> loadMapAndFile(File file)
      Loads a Map and a File from a specified file.
      Parameters:
      file - the file we want to load from
      Returns:
      a Pair of Map and File instances from the specified file
    • loadGame

      public static Game loadGame(File file)
      Loads a Game instance from a specified file.
      Parameters:
      file - the file we want to load from
      Returns:
      a Game instance from the specified file
    • serialize

      public static void serialize(FileOutputStream file, Object obj) throws IOException
      Serializes an Object to a specified file.
      Parameters:
      file - the file we want to serialize to
      obj - the Object we want to serialize
      Throws:
      IOException - if an error occurs
    • saveToStream

      public static void saveToStream(File file, Object obj, String type)
      Serializes an Object to a Stream.
      Parameters:
      file - the file we want to serialize to
      obj - the Object we want to serialize
      type - the extension of the file we serialize to