List of usage examples for java.util Properties forEach
@Override public synchronized void forEach(BiConsumer<? super Object, ? super Object> action)
From source file:com.adeptj.runtime.osgi.FrameworkManager.java
private Map<String, String> loadFrameworkProperties() { Properties props = new Properties(); Map<String, String> configs = new HashMap<>(); Path frameworkConfPath = Environment.getFrameworkConfPath(); if (Environment.isFrameworkConfFileExists()) { try (InputStream is = Files.newInputStream(frameworkConfPath)) { props.load(is);/*from w ww . ja va 2 s . c o m*/ props.forEach((key, val) -> configs.put((String) key, (String) val)); } catch (IOException ex) { LOGGER.error("IOException while loading framework.properties from file system!!", ex); // Fallback is try to load the classpath framework.properties this.loadClasspathFrameworkProperties(props, configs); } } else { this.loadClasspathFrameworkProperties(props, configs); this.createFrameworkPropertiesFile(frameworkConfPath); } return configs; }
From source file:org.ballerinalang.composer.server.launcher.log.LogManagerUtils.java
/** * Read the logging configuration file and replacing the environment variables. * @return The updated properties as an input stream * @throws IOException When log config file cannot be found. *///from www . j av a2s . co m private InputStream readConfiguration() throws IOException { Properties properties = getDefaultLogConfiguration(); properties.forEach((k, v) -> { String val = substituteVariables((String) v); properties.setProperty((String) k, val); }); return propertiesToInputStream(properties); }
From source file:org.nanoframework.commons.loader.PropertiesLoader.java
/** * .//from w w w . j a va 2 s . c om * @param contextPath * @param stream context? * @param loadContext ?context * @throws LoaderException * @throws IOException IO */ @Deprecated public static final void load(final String contextPath, final InputStream stream, final boolean loadContext) throws LoaderException, IOException { final Properties prop = load(stream); prop.forEach((key, value) -> System.setProperty((String) key, (String) value)); PROPERTIES.put(contextPath, prop); if (loadContext) { final String context = prop.getProperty(CONTEXT); if (StringUtils.isNotEmpty(context)) { final String[] ctxs = context.split(";"); if (ctxs.length > 0) { for (String ctx : ctxs) { final Properties properties = load(ctx); if (properties != null) { PROPERTIES.put(ctx, properties); } else { LOGGER.error(ctx + ": !"); } } } } } }
From source file:org.nanoframework.commons.loader.PropertiesLoader.java
/** * .//w ww . ja va 2s. c o m * @param contextPath * @param loadContext ?context * @throws LoaderException * @throws IOException IO */ public static final void load(final String contextPath, final boolean loadContext) throws LoaderException, IOException { final Properties prop = load(contextPath); prop.forEach((key, value) -> System.setProperty((String) key, (String) value)); PROPERTIES.put(contextPath, prop); if (loadContext) { final String context = prop.getProperty(CONTEXT); if (StringUtils.isNotEmpty(context)) { final String[] ctxs = context.split(";"); if (ctxs.length > 0) { for (String ctx : ctxs) { if (StringUtils.isNotBlank(ctx)) { final Properties properties = load(ctx); if (properties != null) { PROPERTIES.put(ctx, properties); } else { LOGGER.error(ctx + ": !"); } } } } } } }
From source file:org.nanoframework.orm.mybatis.plugin.TomcatJdbcPoolDataSourceFactory.java
@Override public void setProperties(Properties properties) { try {/*from ww w. j a v a 2 s . c o m*/ Map<String, Object> map = Maps.newHashMap(); properties.forEach((key, value) -> { if (StringUtils.isNotEmpty((String) value) && ((String) value).startsWith("${") && ((String) value).endsWith("}")) { return; } map.put((String) key, value); }); TomcatJdbcConfig config = TomcatJdbcConfig.mapToBean(map, TomcatJdbcConfig.class); if (TomcatJdbcDataSource != null) { TomcatJdbcDataSource.getMethod("setDriverClassName", String.class).invoke(dataSource, config.getDriver()); TomcatJdbcDataSource.getMethod("setUrl", String.class).invoke(dataSource, config.getUrl()); TomcatJdbcDataSource.getMethod("setUsername", String.class).invoke(dataSource, config.getUserName()); TomcatJdbcDataSource.getMethod("setPassword", String.class).invoke(dataSource, config.getPasswd()); if (config.getInitialSize() != null) { TomcatJdbcDataSource.getMethod("setInitialSize", int.class).invoke(dataSource, config.getInitialSize()); } if (config.getMinIdle() != null) { TomcatJdbcDataSource.getMethod("setMinIdle", int.class).invoke(dataSource, config.getMinIdle()); } if (config.getMaxWait() != null) { TomcatJdbcDataSource.getMethod("setMaxWait", int.class).invoke(dataSource, config.getMaxWait()); } if (config.getMaxActive() != null) { TomcatJdbcDataSource.getMethod("setMaxActive", int.class).invoke(dataSource, config.getMaxActive()); } if (config.getTestWhileIdle() != null) { TomcatJdbcDataSource.getMethod("setTestWhileIdle", boolean.class).invoke(dataSource, config.getTestWhileIdle()); } if (config.getTestOnBorrow() != null) { TomcatJdbcDataSource.getMethod("setTestOnBorrow", boolean.class).invoke(dataSource, config.getTestOnBorrow()); } if (config.getValidationInterval() != null) { TomcatJdbcDataSource.getMethod("setValidationInterval", long.class).invoke(dataSource, config.getValidationInterval()); } if (config.getTimeBetweenEvictionRunsMillis() != null) { TomcatJdbcDataSource.getMethod("setTimeBetweenEvictionRunsMillis", int.class).invoke(dataSource, config.getTimeBetweenEvictionRunsMillis()); } if (config.getLogAbandoned() != null) { TomcatJdbcDataSource.getMethod("setLogAbandoned", boolean.class).invoke(dataSource, config.getLogAbandoned()); } if (config.getRemoveAbandoned() != null) { TomcatJdbcDataSource.getMethod("setRemoveAbandoned", boolean.class).invoke(dataSource, config.getRemoveAbandoned()); } if (config.getRemoveAbandonedTimeout() != null) { TomcatJdbcDataSource.getMethod("setRemoveAbandonedTimeout", int.class).invoke(dataSource, config.getRemoveAbandonedTimeout()); } if (config.getMinEvictableIdleTimeMillis() != null) { TomcatJdbcDataSource.getMethod("setMinEvictableIdleTimeMillis", int.class).invoke(dataSource, config.getMinEvictableIdleTimeMillis()); } if (config.getJdbcInterceptors() != null) { TomcatJdbcDataSource.getMethod("setJdbcInterceptors", String.class).invoke(dataSource, config.getJdbcInterceptors()); } if (config.getJmxEnabled() != null) { TomcatJdbcDataSource.getMethod("setJmxEnabled", boolean.class).invoke(dataSource, config.getJmxEnabled()); } } else { throw new DataSourceException("Unknown class [ org.apache.tomcat.jdbc.pool.DataSource ]"); } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new DataSourceException(e.getMessage(), e); } }