pingtool/Storage.java
2025-05-28 09:42:09 +02:00

33 lines
1.2 KiB
Java

import java.io.*;
import java.util.*;
public class Storage {
private static final String FILE_NAME = "scans.dat";
public static void saveScans(List<StoredScan> storedScans) throws IOException {
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(FILE_NAME))) {
out.writeObject(storedScans);
}
}
@SuppressWarnings("unchecked")
public static List<StoredScan> loadScans() throws IOException, ClassNotFoundException {
File file = new File(FILE_NAME);
if (!file.exists()) return new ArrayList<>();
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(FILE_NAME))) {
return (List<StoredScan>) in.readObject();
}
}
public static class StoredScan implements Serializable {
private static final long serialVersionUID = 1L;
public String type;
public String accessString;
public String customName;
public StoredScan(String type, String accessString, String customName) {
this.type = type;
this.accessString = accessString;
this.customName = customName;
}
}
}