WIZARD_PR2_DOP/Infrastructure/Persistenz.java

75 lines
2.3 KiB
Java
Raw Permalink 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:04:28 +02:00
/*------------------------------------------*/
// statische Konstanten
/*------------------------------------------*/
2023-10-11 17:04:28 +02:00
/*------------------------------------------*/
// statische Attribute(zB. zähler)
/*------------------------------------------*/
final static String FILE_NAME = "WIZARD_DATA_";
/*------------------------------------------*/
// Attribute jedes Objektes
/*------------------------------------------*/
/*------------------------------------------*/
// Konstruktoren (default und spezifische)
/*------------------------------------------*/
/*------------------------------------------*/
// statische Methoden
/*------------------------------------------*/
public static boolean sindDatenVorhanden(String name) {
File f = new File(FILE_NAME + name + ".ser");
2023-10-11 17:04:28 +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:04:28 +02:00
/*------------------------------------------*/
// Getter und Setter
/*------------------------------------------*/
/*------------------------------------------*/
// @Overrides
/*------------------------------------------*/
/*------------------------------------------*/
// öffentliche Methodes
/*------------------------------------------*/
/*------------------------------------------*/
// Hilfsmethoden (privat)
/*------------------------------------------*/
2023-10-05 23:32:29 +02:00
}