Package persistence
Class FileHandler
java.lang.Object
persistence.FileHandler
Implementation of FileHandler class, contains static methods for saving and loading Map and Game state to and from files.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Game
Loads a Game instance from a specified file.static Map
Loads a Map instance from a specified file.loadMapAndFile
(File file) Loads a Map and a File from a specified file.static void
Saves a Game instance to a specified file.static void
Saves a Map instance to a specified file.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.static void
saveToStream
(File file, Object obj, String type) Serializes an Object to a Stream.static void
serialize
(FileOutputStream file, Object obj) Serializes an Object to a specified file.
-
Constructor Details
-
FileHandler
public FileHandler()
-
-
Method Details
-
saveMap
Saves a Map instance to a specified file.- Parameters:
file
- the File we want to save tomap
- the Map instance we want to save
-
saveGame
Saves a Game instance to a specified file.- Parameters:
file
- the File we want to save togame
- the Game instance we want to save
-
saveToJson
The logic of saving an Object state to a specified file with a specified file type.- Parameters:
file
- the File we want to save toobj
- the Object we want to savetype
- the extension of the file we save to
-
loadMap
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
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
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
Serializes an Object to a specified file.- Parameters:
file
- the file we want to serialize toobj
- the Object we want to serialize- Throws:
IOException
- if an error occurs
-
saveToStream
Serializes an Object to a Stream.- Parameters:
file
- the file we want to serialize toobj
- the Object we want to serializetype
- the extension of the file we serialize to
-