/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package buzzerproxy.LIBRARY; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Enger */ public class Serialization { public Serialization() { } public void writeCache(String filename, HashMap> r) { if (filename != null) { try { //use buffering OutputStream file = new FileOutputStream(filename); OutputStream buffer = new BufferedOutputStream(file); ObjectOutput output = new ObjectOutputStream(buffer); try { output.writeObject(r); } finally { output.close(); } } catch (IOException ex) { Logger.getLogger(Serialization.class.getName()).log(Level.SEVERE, "CacheWrite Performance Failed", ex); } } // if ( filename != null ){ } // public void writeCache(String filename, HashMap> r) { public HashMap> readCache(String filename) { HashMap> c = new HashMap>(); try { //use buffering InputStream file = new FileInputStream(filename); InputStream buffer = new BufferedInputStream(file); ObjectInput input = new ObjectInputStream(buffer); try { //deserialize the List c = (HashMap>) input.readObject(); //display its data } finally { input.close(); } } catch (ClassNotFoundException ex) { Logger.getLogger(Serialization.class.getName()).log(Level.SEVERE, "CacheRead Performance Failed", ex); } catch (IOException ex) { Logger.getLogger(Serialization.class.getName()).log(Level.SEVERE, "CacheRead IO Error", ex); } return c; } // public HashMap> readCache(String filename) { } // public class Serialization {