Class GamePersistence
java.lang.Object
org.xxdc.oss.example.GamePersistence
Provides methods for saving and loading a
Game object to/from a file.
The saveTo(File, Game) method writes the provided Game object to the
specified file. The loadFrom(File) method reads a Game object from the specified
file and returns it.
The GamePersistence.GamePersistenceFilter class is used to filter the objects that can be loaded from
the file, rejecting any loaded classes with more than 1000 object references to prevent
deserialization attacks.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
GamePersistence
public GamePersistence()
-
-
Method Details
-
saveTo
Saves the providedGameobject to the specified file.- Parameters:
gameFile- the file to save the game state togame- theGameobject to save- Throws:
IOException- if an I/O error occurs while writing the game state to the file
-
loadFrom
Reads aGameobject from the specified file and returns it.- Parameters:
gameFile- the file to load the game state from- Returns:
- the
Gameobject read from the file - Throws:
IOException- if an I/O error occurs while reading the game state from the fileClassNotFoundException- if theGameclass cannot be found
-