1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package cn.com.ctop.common.utils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import java.io.InputStream;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Properties;
- public class PropertiesUtils {
- private static final Logger log = LoggerFactory.getLogger(PropertiesUtils.class);
- private static Map<String, String> cache = new HashMap<String, String>();
- public static String getConfig(String key) {
- return getValue("kuaishou_config", key);
- }
- public static String getValue(String name, String key) {
- try {
- String cacheValue = (String) cache.get(name + key);
- if (cacheValue != null) {
- return cacheValue;
- }
- Properties props = new Properties();
- InputStream in = PropertiesUtils.class.getResourceAsStream("/"
- + name + ".properties");
- props.load(in);
- String value = props.getProperty(key);
- cache.put(name + key, value);
- props.clone();
- in.close();
- return value;
- } catch (Exception e) {
- log.error("PropertiesUtil getCacheValue Error", e);
- }
- return null;
- }
- public static Map<String, String> getMap(String name) {
- try {
- Properties props = new Properties();
- InputStream in = PropertiesUtils.class.getResourceAsStream("/"
- + name + ".properties");
- props.load(in);
- Iterator<Object> it = props.keySet().iterator();
- Map<String, String> map = new HashMap<String, String>();
- while (it.hasNext()) {
- String key = it.next().toString();
- String value = props.getProperty(key);
- map.put(key, value);
- }
- props.clone();
- in.close();
- return map;
- } catch (Exception e) {
- log.error("PropertiesUtil getMap Error", e);
- }
- return null;
- }
- }
|