1 5 package com.opensymphony.user.provider.file; 6 7 import org.apache.commons.logging.Log; 8 import org.apache.commons.logging.LogFactory; 9 10 import java.io.File ; 11 import java.io.FileOutputStream ; 12 import java.io.ObjectInputStream ; 13 import java.io.ObjectOutputStream ; 14 import java.io.Serializable ; 15 16 17 class SerializableGroupsCache extends FileGroupsCache implements Serializable { 18 20 protected static final Log log = LogFactory.getLog(SerializableGroupsCache.class); 21 22 24 public SerializableGroupsCache(String storeFile, String storeFileType) { 25 super(storeFile, storeFileType); 26 load(); 27 } 28 29 31 public boolean load() { 32 try { 33 ObjectInputStream ois = new ObjectInputStream (getInputStreamFromStoreFile()); 34 SerializableGroupsCache g = (SerializableGroupsCache) ois.readObject(); 35 36 groups = g.groups; 38 39 return true; 40 } catch (Exception e) { 41 log.fatal("cannot load from file " + storeFile + ". Create a new blank store.", e); 42 } 43 44 return false; 45 } 46 47 public boolean store() { 48 try { 49 FileOutputStream fos = new FileOutputStream (new File (storeFile)); 50 ObjectOutputStream oos = new ObjectOutputStream (fos); 51 oos.writeObject(this); 52 fos.close(); 53 54 return true; 55 } catch (Exception e) { 56 log.fatal("cannot store in file " + storeFile + ".", e); 57 } 58 59 return false; 60 } 61 } 62 | Popular Tags |