Refactor to read/write files of graph and map data
This commit is contained in:
27
src/main/java/GraphDataObjectWriter.java
Normal file
27
src/main/java/GraphDataObjectWriter.java
Normal file
@@ -0,0 +1,27 @@
|
||||
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 (FileOutputStream fileOut = new FileOutputStream(filename);
|
||||
ObjectOutputStream out = new ObjectOutputStream(fileOut);
|
||||
){
|
||||
out.writeObject(data);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user