import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class GraphDataObjectWriter {

    private GraphWithMapData data;
    private String filename;

    public GraphDataObjectWriter(String filename, GraphWithMapData data) {
        if(!filename.matches(".*\\.ser")){
            filename = filename + ".ser";
        }
        this.filename = filename;
        this.data = data;
    }

    public void writeDataToFile() {
        try (BufferedOutputStream bufferedOut = new BufferedOutputStream(new FileOutputStream(filename));
             ObjectOutputStream out = new ObjectOutputStream(bufferedOut);
        ){
            out.writeObject(data);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
