Java:
class El {
String schema;
JSONObject header;
JSONObject message;
El(String schema, JSONObject header, JSONObject message) {
this.schema = schema;
this.header = header;
this.message = message;
}
}
private static final LinkedList<El> list = new LinkedList<El>();
public static void saveList1() {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("list1data.txt"))) {
oos.writeInt(list.size());
for (El el : list) {
oos.writeObject(new String[] { el.schema, el.header.toString(), el.message.toString() });
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void loadList1() {
if (new File("list1data.txt").exists()) {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("list1data.txt"))) {
int size = ois.readInt();
for (int i = 0; i < size; i++) {
String[] s = (String[]) ois.readObject();
list.add(new El(s[0], new JSONObject(s[1]), new JSONObject(s[2])));
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
}
Ich denke das ist zu kompliziert, übersehe ich etwas?