WIZARD_PR2_DOP/Infrastructure/Persistenz.java

63 lines
1.9 KiB
Java

/*
============================================================
This is the "Persistenz" file from Author: Philipp Kotte
written on: 05 / 10 / 2023 at: 23:25
============================================================
*/
package Infrastructure;
import Facade.Spiel;
import java.io.*;
public class Persistenz {
/*------------------------------------------*/
// statische Konstanten
/*------------------------------------------*/
/*------------------------------------------*/
// statische Attribute(zB. zähler)
/*------------------------------------------*/
final static String FILE_NAME = "WIZARD_DATA_";
public static boolean sindDatenVorhanden(String name) {
File f = new File(FILE_NAME + name + ".ser");
if (f.exists()) {
return true;
}
return false;
}
public static void speichereDaten(String name, Spiel spiel) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE_NAME + name + ".ser"));
oos.writeObject(spiel);
oos.close();
}
public static Object ladeDaten(String name) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE_NAME + name + ".ser"));
Object spiel = ois.readObject();
ois.close();
return spiel;
}
/*------------------------------------------*/
// Getter und Setter
/*------------------------------------------*/
/*------------------------------------------*/
// @Overrides
/*------------------------------------------*/
/*------------------------------------------*/
// öffentliche Methodes
/*------------------------------------------*/
/*------------------------------------------*/
// Hilfsmethoden (privat)
/*------------------------------------------*/
}