Refactor to read/write files of graph and map data
This commit is contained in:
32
src/main/java/GraphDataObjectReader.java
Normal file
32
src/main/java/GraphDataObjectReader.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
||||
public class GraphDataObjectReader {
|
||||
private GraphWithMapData data;
|
||||
private String filename;
|
||||
|
||||
public GraphDataObjectReader(String filename) throws IOException {
|
||||
if(!filename.matches(".*\\.ser")){
|
||||
filename = filename + ".ser";
|
||||
}
|
||||
this.filename = filename;
|
||||
try(//don't need to close these because of try-with-resources
|
||||
FileInputStream fileIn = new FileInputStream(filename);
|
||||
ObjectInputStream in = new ObjectInputStream(fileIn))
|
||||
{
|
||||
data = (GraphWithMapData) in.readObject();
|
||||
} catch (FileNotFoundException | ClassNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public GraphWithMapData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user