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 SerializableUsersCache extends FileUsersCache implements Serializable { 18 20 private static final Log log = LogFactory.getLog(SerializableUsersCache.class); 21 22 24 public SerializableUsersCache(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 SerializableUsersCache u = (SerializableUsersCache) ois.readObject(); 35 36 users = u.users; 37 38 return true; 39 } catch (Exception e) { 40 log.fatal("cannot load from file " + storeFile + ". Create a new blank store.", e); 41 } 42 43 return false; 44 } 45 46 public boolean store() { 47 try { 48 FileOutputStream fos = new FileOutputStream (new File (storeFile)); 49 ObjectOutputStream oos = new ObjectOutputStream (fos); 50 oos.writeObject(this); 51 fos.close(); 52 53 return true; 54 } catch (Exception e) { 55 log.fatal("cannot store in file " + storeFile + ".", e); 56 } 57 58 return false; 59 } 60 } 61 | Popular Tags |