46 lines
1.4 KiB
Java
46 lines
1.4 KiB
Java
import org.jgrapht.Graph;
|
|
|
|
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;
|
|
private boolean verbose = true;
|
|
|
|
public GraphDataObjectWriter(String filename, GraphWithMapData data) {
|
|
if(!filename.matches(".*\\.ser")){
|
|
filename = filename + ".ser";
|
|
}
|
|
this.filename = filename;
|
|
this.data = data;
|
|
}
|
|
|
|
public GraphDataObjectWriter(String filename, GraphWithMapData data, boolean verbose) {
|
|
this.verbose = verbose;
|
|
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);
|
|
){
|
|
if(verbose) {
|
|
System.out.println("Writing graph and occupancy data to file. This may take some time.");
|
|
System.out.println("File I/O time is not included in results.");
|
|
}
|
|
out.writeObject(data);
|
|
} catch (IOException ex) {
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
}
|