WIZARD_PR2_DOP/Infrastructure/Persistenz.java

63 lines
1.9 KiB
Java
Raw Normal View History

2023-10-05 23:32:29 +02:00
/*
============================================================
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.*;
2023-10-05 23:32:29 +02:00
public class Persistenz {
2023-10-11 17:29:08 +02:00
/*------------------------------------------*/
// statische Konstanten
/*------------------------------------------*/
/*------------------------------------------*/
// statische Attribute(zB. zähler)
/*------------------------------------------*/
2023-10-11 17:27:43 +02:00
final static String FILE_NAME = "WIZARD_DATA_";
2023-10-11 17:27:43 +02:00
public static boolean sindDatenVorhanden(String name) {
File f = new File(FILE_NAME + name + ".ser");
2023-10-11 17:27:43 +02:00
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;
}
2023-10-11 17:29:08 +02:00
/*------------------------------------------*/
// Getter und Setter
/*------------------------------------------*/
/*------------------------------------------*/
// @Overrides
/*------------------------------------------*/
/*------------------------------------------*/
// öffentliche Methodes
/*------------------------------------------*/
/*------------------------------------------*/
// Hilfsmethoden (privat)
/*------------------------------------------*/
2023-10-05 23:32:29 +02:00
}