1 package example; 2 3 import java.net.*; 4 import java.io.*; 5 6 import com.caucho.vfs.*; 7 8 public class AppConfig { 9 ConfigFilesLocation _cfl = null; 10 11 17 public void setConfigFilesLocation(String location) 18 throws Exception 19 { 20 _cfl = new ConfigFilesLocation(); 21 _cfl.setLocation(location); 22 } 23 24 public void init() 25 throws Exception 26 { 27 if (_cfl == null) 28 throw new Exception ("'config-files-location' must be set"); 29 } 30 31 41 public ReadStream openConfigFileRead(String file) 42 throws IOException 43 { 44 return _cfl.openRead(file); 45 } 46 47 57 public WriteStream openConfigFileWrite(String file) 58 throws IOException 59 { 60 return _cfl.openWrite(file); 61 } 62 63 public static class ConfigFilesLocation { 64 Path _path; 66 public void setLocation(String location) 67 { 68 _path = Vfs.lookup(location); 69 } 70 71 public ReadStream openRead(String file) 72 throws IOException 73 { 74 Path p = _path.lookup(file); 75 return p.openRead(); 76 } 77 78 public WriteStream openWrite(String file) 79 throws IOException 80 { 81 Path p = _path.lookup(file); 82 return p.openWrite(); 83 } 84 } 85 } 86 | Popular Tags |