1 package perf; 2 3 import java.io.InputStream ; 4 import java.util.Properties ; 5 6 7 12 class Configuration { 13 private String resource; 14 15 Configuration() { 16 this.resource = "/jiapi.properties"; 17 } 18 19 Configuration(String resource) { 20 this.resource = resource; 21 } 22 23 24 boolean getBoolean(String key) { 25 if (key == null) { 26 return false; 27 } 28 29 Properties p = getProperties(resource); 30 String s = p.getProperty(key); 31 32 boolean b = false; 33 try { 34 b = Boolean.valueOf(s).booleanValue(); 35 } 36 catch(Exception e) { 37 } 38 39 return b; 40 } 41 42 43 private Properties getProperties(String name) { 44 Properties properties = new Properties (); 45 46 try { 47 InputStream is = getClass().getResourceAsStream(name); 48 if (is != null) { 49 properties.load(is); 50 } 51 else { 52 System.out.println("Could not find resource: " + name); 53 } 54 } 55 catch (Exception e) { 56 System.out.println("Failed to get property file " + name + 57 ", " + e); 58 } 59 60 return properties; 61 } 62 } 63 | Popular Tags |