@Test public void testme() throws IOException{ Map<String, Object> m1 = ConfigLoader.load("ak47"); Assert.assertTrue( m1 != null ); }
@SuppressWarnings("unchecked") public static Map<String, Object> load(String prefix) throws IOException { Map<String, Object> omap; Yaml yaml = new Yaml(); String testYmlName = prefix + POSTFIX_TEST_YML; String ymlName = prefix + POSTFIX_YML; System.out.println(CLASS_LOADER.getResource("")); InputStream testYmlIs = CLASS_LOADER.getResourceAsStream(testYmlName); if (null == testYmlIs) { InputStream ymlIs = CLASS_LOADER.getResourceAsStream(ymlName); if (null == ymlIs) { log.error("NOT found {} and {}.", testYmlName, ymlName); throw new Ak47RuntimeException(testYmlName + " and " + ymlName + " both NOT found."); } try { omap = (Map<String, Object>) yaml.load(ymlIs); } catch (Exception e) { log.error("load {} fail.", ymlName); throw new Ak47RuntimeException("load " + ymlName + " fail.", e); } finally { ymlIs.close(); } log.info("load {} success.", ymlName); } else { try { omap = (Map<String, Object>) yaml.load(testYmlIs); } catch (Exception e) { log.error("load {} fail.", testYmlName); throw new Ak47RuntimeException( "load " + testYmlName + " fail.", e); } finally { testYmlIs.close(); } log.info("load {} success.", testYmlName); } if (omap == null || omap.size() == 0) { throw new Ak47RuntimeException("load " + testYmlName + " or " + ymlName + " fail."); } String appConfYmlPath = Ak47Env.AK47_HOME_CONF_DIR + File.separator + ymlName; File appConfYmlFile = new File(appConfYmlPath); if (!appConfYmlFile.exists()) { log.info("NOT found {}.", appConfYmlPath); } else if (!appConfYmlFile.canRead()) { log.warn("Can NOT read {}.", appConfYmlPath); } else { FileInputStream fis = new FileInputStream(appConfYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail. result is null."); } log.info("load {} success.", appConfYmlPath); newCoverOld(omap, newMap); } String homeYmlPath = Ak47Env.AK47_LOCAL_SHARE_DIR + File.separator + ymlName; File homeYmlFile = new File(homeYmlPath); if (!homeYmlFile.exists()) { log.info("NOT found {}.", homeYmlPath); } else if (!homeYmlFile.canRead()) { log.warn("can NOT read {}.", homeYmlPath); } else { FileInputStream fis = new FileInputStream(homeYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException( "load " + homeYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException("load " + homeYmlPath + " fail. result is null."); } log.info("load {} success.", homeYmlPath); newCoverOld(omap, newMap); } return omap; }
ConfigLoader { @SuppressWarnings("unchecked") public static Map<String, Object> load(String prefix) throws IOException { Map<String, Object> omap; Yaml yaml = new Yaml(); String testYmlName = prefix + POSTFIX_TEST_YML; String ymlName = prefix + POSTFIX_YML; System.out.println(CLASS_LOADER.getResource("")); InputStream testYmlIs = CLASS_LOADER.getResourceAsStream(testYmlName); if (null == testYmlIs) { InputStream ymlIs = CLASS_LOADER.getResourceAsStream(ymlName); if (null == ymlIs) { log.error("NOT found {} and {}.", testYmlName, ymlName); throw new Ak47RuntimeException(testYmlName + " and " + ymlName + " both NOT found."); } try { omap = (Map<String, Object>) yaml.load(ymlIs); } catch (Exception e) { log.error("load {} fail.", ymlName); throw new Ak47RuntimeException("load " + ymlName + " fail.", e); } finally { ymlIs.close(); } log.info("load {} success.", ymlName); } else { try { omap = (Map<String, Object>) yaml.load(testYmlIs); } catch (Exception e) { log.error("load {} fail.", testYmlName); throw new Ak47RuntimeException( "load " + testYmlName + " fail.", e); } finally { testYmlIs.close(); } log.info("load {} success.", testYmlName); } if (omap == null || omap.size() == 0) { throw new Ak47RuntimeException("load " + testYmlName + " or " + ymlName + " fail."); } String appConfYmlPath = Ak47Env.AK47_HOME_CONF_DIR + File.separator + ymlName; File appConfYmlFile = new File(appConfYmlPath); if (!appConfYmlFile.exists()) { log.info("NOT found {}.", appConfYmlPath); } else if (!appConfYmlFile.canRead()) { log.warn("Can NOT read {}.", appConfYmlPath); } else { FileInputStream fis = new FileInputStream(appConfYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail. result is null."); } log.info("load {} success.", appConfYmlPath); newCoverOld(omap, newMap); } String homeYmlPath = Ak47Env.AK47_LOCAL_SHARE_DIR + File.separator + ymlName; File homeYmlFile = new File(homeYmlPath); if (!homeYmlFile.exists()) { log.info("NOT found {}.", homeYmlPath); } else if (!homeYmlFile.canRead()) { log.warn("can NOT read {}.", homeYmlPath); } else { FileInputStream fis = new FileInputStream(homeYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException( "load " + homeYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException("load " + homeYmlPath + " fail. result is null."); } log.info("load {} success.", homeYmlPath); newCoverOld(omap, newMap); } return omap; } }
ConfigLoader { @SuppressWarnings("unchecked") public static Map<String, Object> load(String prefix) throws IOException { Map<String, Object> omap; Yaml yaml = new Yaml(); String testYmlName = prefix + POSTFIX_TEST_YML; String ymlName = prefix + POSTFIX_YML; System.out.println(CLASS_LOADER.getResource("")); InputStream testYmlIs = CLASS_LOADER.getResourceAsStream(testYmlName); if (null == testYmlIs) { InputStream ymlIs = CLASS_LOADER.getResourceAsStream(ymlName); if (null == ymlIs) { log.error("NOT found {} and {}.", testYmlName, ymlName); throw new Ak47RuntimeException(testYmlName + " and " + ymlName + " both NOT found."); } try { omap = (Map<String, Object>) yaml.load(ymlIs); } catch (Exception e) { log.error("load {} fail.", ymlName); throw new Ak47RuntimeException("load " + ymlName + " fail.", e); } finally { ymlIs.close(); } log.info("load {} success.", ymlName); } else { try { omap = (Map<String, Object>) yaml.load(testYmlIs); } catch (Exception e) { log.error("load {} fail.", testYmlName); throw new Ak47RuntimeException( "load " + testYmlName + " fail.", e); } finally { testYmlIs.close(); } log.info("load {} success.", testYmlName); } if (omap == null || omap.size() == 0) { throw new Ak47RuntimeException("load " + testYmlName + " or " + ymlName + " fail."); } String appConfYmlPath = Ak47Env.AK47_HOME_CONF_DIR + File.separator + ymlName; File appConfYmlFile = new File(appConfYmlPath); if (!appConfYmlFile.exists()) { log.info("NOT found {}.", appConfYmlPath); } else if (!appConfYmlFile.canRead()) { log.warn("Can NOT read {}.", appConfYmlPath); } else { FileInputStream fis = new FileInputStream(appConfYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail. result is null."); } log.info("load {} success.", appConfYmlPath); newCoverOld(omap, newMap); } String homeYmlPath = Ak47Env.AK47_LOCAL_SHARE_DIR + File.separator + ymlName; File homeYmlFile = new File(homeYmlPath); if (!homeYmlFile.exists()) { log.info("NOT found {}.", homeYmlPath); } else if (!homeYmlFile.canRead()) { log.warn("can NOT read {}.", homeYmlPath); } else { FileInputStream fis = new FileInputStream(homeYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException( "load " + homeYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException("load " + homeYmlPath + " fail. result is null."); } log.info("load {} success.", homeYmlPath); newCoverOld(omap, newMap); } return omap; }  }
ConfigLoader { @SuppressWarnings("unchecked") public static Map<String, Object> load(String prefix) throws IOException { Map<String, Object> omap; Yaml yaml = new Yaml(); String testYmlName = prefix + POSTFIX_TEST_YML; String ymlName = prefix + POSTFIX_YML; System.out.println(CLASS_LOADER.getResource("")); InputStream testYmlIs = CLASS_LOADER.getResourceAsStream(testYmlName); if (null == testYmlIs) { InputStream ymlIs = CLASS_LOADER.getResourceAsStream(ymlName); if (null == ymlIs) { log.error("NOT found {} and {}.", testYmlName, ymlName); throw new Ak47RuntimeException(testYmlName + " and " + ymlName + " both NOT found."); } try { omap = (Map<String, Object>) yaml.load(ymlIs); } catch (Exception e) { log.error("load {} fail.", ymlName); throw new Ak47RuntimeException("load " + ymlName + " fail.", e); } finally { ymlIs.close(); } log.info("load {} success.", ymlName); } else { try { omap = (Map<String, Object>) yaml.load(testYmlIs); } catch (Exception e) { log.error("load {} fail.", testYmlName); throw new Ak47RuntimeException( "load " + testYmlName + " fail.", e); } finally { testYmlIs.close(); } log.info("load {} success.", testYmlName); } if (omap == null || omap.size() == 0) { throw new Ak47RuntimeException("load " + testYmlName + " or " + ymlName + " fail."); } String appConfYmlPath = Ak47Env.AK47_HOME_CONF_DIR + File.separator + ymlName; File appConfYmlFile = new File(appConfYmlPath); if (!appConfYmlFile.exists()) { log.info("NOT found {}.", appConfYmlPath); } else if (!appConfYmlFile.canRead()) { log.warn("Can NOT read {}.", appConfYmlPath); } else { FileInputStream fis = new FileInputStream(appConfYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail. result is null."); } log.info("load {} success.", appConfYmlPath); newCoverOld(omap, newMap); } String homeYmlPath = Ak47Env.AK47_LOCAL_SHARE_DIR + File.separator + ymlName; File homeYmlFile = new File(homeYmlPath); if (!homeYmlFile.exists()) { log.info("NOT found {}.", homeYmlPath); } else if (!homeYmlFile.canRead()) { log.warn("can NOT read {}.", homeYmlPath); } else { FileInputStream fis = new FileInputStream(homeYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException( "load " + homeYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException("load " + homeYmlPath + " fail. result is null."); } log.info("load {} success.", homeYmlPath); newCoverOld(omap, newMap); } return omap; }  @SuppressWarnings("unchecked") static Map<String, Object> load(String prefix); }
ConfigLoader { @SuppressWarnings("unchecked") public static Map<String, Object> load(String prefix) throws IOException { Map<String, Object> omap; Yaml yaml = new Yaml(); String testYmlName = prefix + POSTFIX_TEST_YML; String ymlName = prefix + POSTFIX_YML; System.out.println(CLASS_LOADER.getResource("")); InputStream testYmlIs = CLASS_LOADER.getResourceAsStream(testYmlName); if (null == testYmlIs) { InputStream ymlIs = CLASS_LOADER.getResourceAsStream(ymlName); if (null == ymlIs) { log.error("NOT found {} and {}.", testYmlName, ymlName); throw new Ak47RuntimeException(testYmlName + " and " + ymlName + " both NOT found."); } try { omap = (Map<String, Object>) yaml.load(ymlIs); } catch (Exception e) { log.error("load {} fail.", ymlName); throw new Ak47RuntimeException("load " + ymlName + " fail.", e); } finally { ymlIs.close(); } log.info("load {} success.", ymlName); } else { try { omap = (Map<String, Object>) yaml.load(testYmlIs); } catch (Exception e) { log.error("load {} fail.", testYmlName); throw new Ak47RuntimeException( "load " + testYmlName + " fail.", e); } finally { testYmlIs.close(); } log.info("load {} success.", testYmlName); } if (omap == null || omap.size() == 0) { throw new Ak47RuntimeException("load " + testYmlName + " or " + ymlName + " fail."); } String appConfYmlPath = Ak47Env.AK47_HOME_CONF_DIR + File.separator + ymlName; File appConfYmlFile = new File(appConfYmlPath); if (!appConfYmlFile.exists()) { log.info("NOT found {}.", appConfYmlPath); } else if (!appConfYmlFile.canRead()) { log.warn("Can NOT read {}.", appConfYmlPath); } else { FileInputStream fis = new FileInputStream(appConfYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", appConfYmlPath); throw new Ak47RuntimeException("load " + appConfYmlPath + " fail. result is null."); } log.info("load {} success.", appConfYmlPath); newCoverOld(omap, newMap); } String homeYmlPath = Ak47Env.AK47_LOCAL_SHARE_DIR + File.separator + ymlName; File homeYmlFile = new File(homeYmlPath); if (!homeYmlFile.exists()) { log.info("NOT found {}.", homeYmlPath); } else if (!homeYmlFile.canRead()) { log.warn("can NOT read {}.", homeYmlPath); } else { FileInputStream fis = new FileInputStream(homeYmlFile); Map<String, Object> newMap; try { newMap = (Map<String, Object>) yaml.load(fis); } catch (Exception e) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException( "load " + homeYmlPath + " fail.", e); } finally { fis.close(); } if (null == newMap) { log.error("load {} fail.", homeYmlPath); throw new Ak47RuntimeException("load " + homeYmlPath + " fail. result is null."); } log.info("load {} success.", homeYmlPath); newCoverOld(omap, newMap); } return omap; }  @SuppressWarnings("unchecked") static Map<String, Object> load(String prefix);  }