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.FileInputStream ; 11 import java.io.IOException ; 12 import java.io.InputStream ; 13 14 17 abstract class FileEntitiesCache { 18 20 protected static final Log log = LogFactory.getLog(FileEntitiesCache.class); 21 22 24 protected String storeFile; 25 protected String storeFileType; 26 27 29 public FileEntitiesCache(String storeFile, String storeFileType) { 30 this.storeFile = storeFile; 31 this.storeFileType = storeFileType; 32 33 if (storeFile == null) { 34 log.fatal("property storeFile must be specified"); 35 } 36 37 if (storeFileType == null) { 38 log.fatal("property storeFileType must be specified; one of (file,resource)"); 39 } 40 41 if (!storeFileType.equalsIgnoreCase("file") && !storeFileType.equalsIgnoreCase("resource")) { 42 log.fatal("property storeFileType must be one of (file,resource)"); 43 } 44 45 } 46 47 49 abstract public boolean load(); 50 51 abstract public boolean store(); 52 53 protected InputStream getInputStreamFromStoreFile() throws IOException { 54 if (storeFileType.equalsIgnoreCase("file")) { 55 return new FileInputStream (storeFile); 56 } else if (storeFileType.equalsIgnoreCase("resource")) { 57 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 58 59 return classLoader.getResourceAsStream(storeFile); 60 } else { 61 log.fatal("property storeFileType must be one of (file,resource)"); 62 63 return null; 64 } 65 } 66 } 67 | Popular Tags |