List of usage examples for java.util Properties forEach
@Override public synchronized void forEach(BiConsumer<? super Object, ? super Object> action)
From source file:uk.ac.kcl.Main.java
public static void main(String[] args) { File folder = new File(args[0]); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File listOfFile : listOfFiles) { if (listOfFile.isFile()) { if (listOfFile.getName().endsWith(".properties")) { System.out.println("Properties sile found:" + listOfFile.getName() + ". Attempting to launch application context"); Properties properties = new Properties(); InputStream input; try { input = new FileInputStream(listOfFile); properties.load(input); if (properties.getProperty("globalSocketTimeout") != null) { TcpHelper.setSocketTimeout( Integer.valueOf(properties.getProperty("globalSocketTimeout"))); }/*w w w. j a v a2s . c o m*/ Map<String, Object> map = new HashMap<>(); properties.forEach((k, v) -> { map.put(k.toString(), v); }); ConfigurableEnvironment environment = new StandardEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new MapPropertySource(listOfFile.getName(), map)); @SuppressWarnings("resource") AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.registerShutdownHook(); ctx.setEnvironment(environment); String scheduling; try { scheduling = properties.getProperty("scheduler.useScheduling"); if (scheduling.equalsIgnoreCase("true")) { ctx.register(ScheduledJobLauncher.class); ctx.refresh(); } else if (scheduling.equalsIgnoreCase("false")) { ctx.register(SingleJobLauncher.class); ctx.refresh(); SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class); launcher.launchJob(); } else if (scheduling.equalsIgnoreCase("slave")) { ctx.register(JobConfiguration.class); ctx.refresh(); } else { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (NullPointerException ex) { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:io.silverware.microservices.Boot.java
/** * Creates initial context pre-filled with system properties, command line arguments, custom property file and default property file. * * @param args Command line arguments./* w w w . j a v a 2s . c o m*/ * @return Initial context pre-filled with system properties, command line arguments, custom property file and default property file. */ @SuppressWarnings("static-access") private static Context getInitialContext(final String... args) { final Context context = new Context(); final Map<String, Object> contextProperties = context.getProperties(); final Options options = new Options(); final CommandLineParser commandLineParser = new DefaultParser(); System.getProperties().forEach((key, value) -> contextProperties.put((String) key, value)); options.addOption(Option.builder(PROPERTY_LETTER).argName("property=value").numberOfArgs(2).valueSeparator() .desc("system properties").build()); options.addOption(Option.builder(PROPERTY_FILE_LETTER).longOpt("properties").desc("Custom property file") .hasArg().argName("PROPERTY_FILE").build()); try { final CommandLine commandLine = commandLineParser.parse(options, args); commandLine.getOptionProperties(PROPERTY_LETTER) .forEach((key, value) -> contextProperties.put((String) key, value)); // process custom properties file if (commandLine.hasOption(PROPERTY_FILE_LETTER)) { final File propertiesFile = new File(commandLine.getOptionValue(PROPERTY_FILE_LETTER)); if (propertiesFile.exists()) { final Properties props = loadProperties(); props.forEach((key, val) -> contextProperties.putIfAbsent(key.toString(), val)); } else { log.error("Specified property file %s does not exists.", propertiesFile.getAbsolutePath()); } } } catch (ParseException pe) { log.error("Cannot parse arguments: ", pe); new HelpFormatter().printHelp("SilverWare usage:", options); System.exit(1); } // now add in default properties from silverware.properties on a classpath loadProperties().forEach((key, val) -> contextProperties.putIfAbsent(key.toString(), val)); context.getProperties().put(Executor.SHUTDOWN_HOOK, "true"); return context; }
From source file:com.u2apple.tool.service.IdentifyAnalyticsService.java
private static Map loadModels() { Map<String, String> map = new HashMap<>(); Properties props = new Properties(); try {//www. ja v a 2 s . co m props.load(IdentifyAnalyticsService.class.getResourceAsStream(Constants.MODELS)); props.forEach((Object key, Object value) -> { String productId = (String) key; String model = AndroidDeviceUtils.formatModel((String) value); if (model.contains(",")) { String[] models = model.split(","); for (String m : models) { map.put(m.trim(), productId); } } else { map.put(model, productId); } }); } catch (IOException ex) { Logger.getLogger(IdentifyAnalyticsService.class.getName()).log(Level.SEVERE, null, ex); } return map; }
From source file:com.qwazr.server.configuration.ServerConfiguration.java
protected static Map<String, String> argsToMap(final String... args) throws IOException { final Map<String, String> props = argsToMapPrefix("--", args); // Load the QWAZR_PROPERTIES String propertyFile = props.get(QWAZR_PROPERTIES); if (propertyFile == null) propertyFile = System.getProperty(QWAZR_PROPERTIES, System.getenv(QWAZR_PROPERTIES)); if (propertyFile != null) { final Path propFile = Paths.get(propertyFile); LOGGER.info(() -> "Load QWAZR_PROPERTIES file: " + propFile.toAbsolutePath()); final Properties properties = new Properties(); try (final BufferedReader reader = Files.newBufferedReader(propFile, StandardCharsets.UTF_8)) { properties.load(reader);// ww w .ja v a 2 s .c om } // Priority to program argument, we only put the value if the key is not present properties.forEach((key, value) -> props.putIfAbsent(key.toString(), value.toString())); } return props; }
From source file:com.github.pjungermann.config.types.properties.PropertiesConverter.java
@NotNull @Override//from w w w . j av a2 s . c o m public Config from(@NotNull final Properties convertible) { final Config config = new Config(); final Map<String, Object> syncConfig = synchronizedMap(config); convertible.forEach((key, value) -> syncConfig.put(key.toString(), value)); return config; }
From source file:bjerne.gallery.service.impl.GalleryRootDirConfigJob.java
private void updateConfigFromFile() throws IOException { LOG.debug("Entering updateConfigFromFile()"); Collection<GalleryRootDir> newRootDirs = new ArrayList<>(); Properties prop = new Properties(); prop.load(new FileReader(configFile)); prop.forEach((k, v) -> { String[] split = ((String) k).split("\\."); if (split.length == 2) { GalleryRootDir oneRootDir = new GalleryRootDir(); newRootDirs.add(oneRootDir); oneRootDir.setRole(split[0]); oneRootDir.setName(split[1]); oneRootDir.setDir(new File(v.toString())); }//from w w w.j a v a2s. c om }); rootDirs = newRootDirs; galleryRootDirChangeListeners.forEach(r -> r.setRootDirs(rootDirs)); }
From source file:com.adeptj.runtime.osgi.FrameworkManager.java
private void loadClasspathFrameworkProperties(Properties props, Map<String, String> configs) { try (InputStream is = FrameworkManager.class.getResourceAsStream(FRAMEWORK_PROPERTIES)) { props.load(is);/*from w w w . j a v a2s.c o m*/ props.forEach((key, val) -> configs.put((String) key, (String) val)); } catch (IOException exception) { LOGGER.error("IOException while loading framework.properties from classpath!!", exception); } }
From source file:com.github.ukase.toolkit.jar.JarSource.java
@Autowired public JarSource(CompoundTemplateLoader templateLoader, UkaseSettings settings) { this.templateLoader = templateLoader; if (settings.getJar() == null) { classLoader = null;/*from w w w .java 2s . c om*/ fonts = Collections.emptyList(); return; } try { URL jar = settings.getJar().toURI().toURL(); Collection<String> props = templateLoader.getResources(IS_HELPERS_CONFIGURATION); Properties properties = new Properties(); props.stream().map(templateLoader::getResource).filter(entry -> entry != null).map(this::mapZipEntry) .filter(stream -> stream != null).forEach(stream -> loadStreamToProperties(stream, properties)); properties.forEach(this::registerHelper); fonts = templateLoader.getResources(IS_FONT).parallelStream().map(font -> "jar:" + jar + "!/" + font) .collect(Collectors.toList()); if (hasHelpers()) { URL[] jars = new URL[] { jar }; classLoader = new URLClassLoader(jars, getClass().getClassLoader()); helpers.forEach((name, className) -> helpersInstances.put(name, getHelper(className))); } else { classLoader = null; } } catch (IOException e) { throw new IllegalStateException("Wrong configuration", e); } }
From source file:com.lrs.enviroment.Metadata.java
private void loadProperties(InputStream input) { try {//from w w w .j av a 2 s. c o m Properties prop = new Properties(); prop.load(input); prop.forEach((k, v) -> delegateMap.put((String) k, v)); } catch (IOException ex) { Logger.getLogger(Metadata.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.adeptj.runtime.osgi.FrameworkManager.java
private Map<String, String> loadFrameworkProperties() { Properties props = new Properties(); Map<String, String> configs = new HashMap<>(); if (Environment.isFrameworkConfFileExists()) { try (InputStream is = Files.newInputStream(Environment.getFrameworkConfPath())) { props.load(is);// www . j a v a2s. co 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(); } return configs; }