@Test public void testLoadFromClasspath() throws EtiqetException { String configPath = "/properties/test.properties"; Map<String, String> properties = PropertiesFileReader.loadFromClasspath(configPath); assertFalse(properties.isEmpty()); assertEquals(12, properties.size()); assertEquals("config.properties", properties.get("fix.config.file.path")); assertEquals("server.cfg", properties.get("fix.server.config.file.path")); assertEquals("database.properties", properties.get("shell.database.properties.path")); assertEquals("remoteshell.properties", properties.get("shell.remoteshell.properties.path")); assertEquals("protocolConfig.properties", properties.get("config.protocol.file.path")); assertEquals("true", properties.get("test.boolean.true")); assertEquals("1", properties.get("test.boolean.convert.true")); assertEquals("false", properties.get("test.boolean.false")); assertEquals("0", properties.get("test.boolean.convert.false")); assertEquals("20", properties.get("test.int")); assertEquals("25.3", properties.get("test.double")); assertEquals("etiqet-core/src/test/resources/properties/testConfig.properties", properties.get("config.client.file.path")); }
public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName); }
PropertiesFileReader { public static Map<String, String> loadFromClasspath(String fileName) throws EtiqetException { Map<String, String> propertyMap = new HashMap<>(); InputStream stream = PropertiesFileReader.class.getResourceAsStream(fileName); Properties p = new Properties(); try { p.load(stream); Enumeration<?> keys = p.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); propertyMap.put(key, p.getProperty(key)); } stream.close(); } catch (Exception e) { throw new EtiqetException("Could not read classpath file " + fileName, e); } return propertyMap; } private  PropertiesFileReader(); static Config loadPropertiesFile(String fileName); static Map<String, String> loadFromClasspath(String fileName);  }