package ki.zoe.library;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/////////////////////////////////////////////////////
// Loader Class provides input and output serial- //
// ization ad flattening of Access lists //
// //
/////////////////////////////////////////////////////
class Loader {
Access access = new Access();
// Saves the Virutal Data Structure as a binary object to
// the specified file name.
protected void saveVDS(Access vds, String filename) {
access = vds;
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(access);
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
// Restores the Virtual Data Structure from the filename and
// returns it to an Access object. If no file exists, then a
// new blank VDS is created and then returned to the Access
// object.
protected Access restoreVDS(String filename) {
Access vds = new Access();
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream(filename);
in = new ObjectInputStream(fis);
vds = (Access) in.readObject();
in.close();
} catch(IOException ex) {
saveVDS(vds,filename);
} catch(ClassNotFoundException es){
es.printStackTrace();
}
return vds;
}
}