List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.meyling.telnet.startup.TelnetD.java
/** * Factory method to create a TelnetD singleton instance, loading the * standard properties files from the location * <code>config/telnetd.properties</code>. * * @return TenetD instance that has been properly set up according to the * passed in properties, and is ready to start serving. * @throws BootException Setup process failed. *//* w w w .j a va 2 s . c o m*/ public static TelnetD createTelnetD() throws BootException { try { Properties properties = new Properties(); // try to load properties from classpath properties.load(new FileInputStream("plugins/telnetd.properties")); return createTelnetD(properties); } catch (IOException e) { trace.fatal(e, e); throw new BootException("Failed to load configuration file."); } }
From source file:com.nts.alphamale.data.Settings.java
public static void loadSettings() { if (new File(SETTINGS).exists()) { Properties prop = new Properties(); try {/*from w ww . j av a 2 s .c om*/ prop.load(new FileReader(SETTINGS)); if (prop.getProperty("command_timeout") != null) EXECUTOR_TIMEOUT = Long.parseLong(prop.getProperty("command_timeout")); if (prop.getProperty("double_tap_threshold") != null) DOUBLE_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("double_tap_threshold")); if (prop.getProperty("long_tap_threshold") != null) LONG_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("long_tap_threshold")); if (prop.getProperty("swipe_area_threshold") != null) SWIPE_AREA_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_area_threshold")); if (prop.getProperty("swipe_angle_threshold") != null) SWIPE_ANGLE_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_angle_threshold")); if (prop.getProperty("find_timeout") != null) FIND_ELEMENT_TIMEOUT = Long.parseLong(prop.getProperty("find_timeout")); if (prop.getProperty("idle_timeout") != null) WAIT_FOR_IDLE_TIMEOUT = Integer.parseInt(prop.getProperty("idle_timeout")); if (prop.getProperty("orientation_schedule") != null) ORIENTATION_SCHEDULE = Long.parseLong(prop.getProperty("orientation_schedule")); if (prop.getProperty("keypad_schedule") != null) KEYPAD_SCHEDULE = Long.parseLong(prop.getProperty("keypad_schedule")); if (prop.getProperty("event_interval") != null) EVENT_INTERVAL = Integer.parseInt(prop.getProperty("event_interval")); if (prop.getProperty("touchscreen_device") != null) TOUCH_DEVICE = prop.getProperty("touchscreen_device"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { FileWriterWithEncoding fw = null; String lineSeparator = System.getProperty("line.separator"); try { fw = new FileWriterWithEncoding(SETTINGS, "UTF-8"); fw.write("# command timeout(ms)" + lineSeparator); fw.write("command_timeout = 5000" + lineSeparator); fw.write(lineSeparator); fw.write("# double tap threshold(sec)" + lineSeparator); fw.write("double_tap_threshold = 0.7" + lineSeparator); fw.write(lineSeparator); fw.write("# long tap threshold(sec)" + lineSeparator); fw.write("long_tap_threshold = 0.7" + lineSeparator); fw.write(lineSeparator); fw.write("# swipe area threshold(px)" + lineSeparator); fw.write("swipe_area_threshold = 100" + lineSeparator); fw.write(lineSeparator); fw.write("# swipe angle threshold" + lineSeparator); fw.write("swipe_angle_threshold = 45" + lineSeparator); fw.write(lineSeparator); fw.write("# find element threshold(ms)" + lineSeparator); fw.write("find_timeout = 2000" + lineSeparator); fw.write(lineSeparator); fw.write("# idle threshold(ms)" + lineSeparator); fw.write("idle_timeout = 2000" + lineSeparator); fw.write(lineSeparator); fw.write("# orientation recognition schedule" + lineSeparator); fw.write("orientation_schedule = 500" + lineSeparator); fw.write(lineSeparator); fw.write("# keypad recognition schedule" + lineSeparator); fw.write("keypad_schedule = 500" + lineSeparator); fw.write(lineSeparator); fw.write("# follower event injection interval(ms)" + lineSeparator); fw.write("event_interval = 500" + lineSeparator); fw.write(lineSeparator); fw.write("# touch screen device" + lineSeparator); fw.write( "touchscreen_device = _touchscreen,touch_dev,clearpad,sensor00,atmel_mxt_540s,synaptics_rmi,mtk-tpd"); } catch (IOException e) { e.printStackTrace(); } finally { try { fw.close(); } catch (IOException e) { } } } }
From source file:net.firejack.platform.core.utils.MiscUtils.java
/** * @param properties//from w w w .j a va 2 s . c o m * @return */ public static Map<String, String> getProperties(File properties) { if (properties == null || !properties.exists()) { return Collections.emptyMap(); } Properties props = new Properties(); FileInputStream stream = null; try { stream = new FileInputStream(properties); props.load(stream); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } Map<String, String> propertiesMap = new HashMap<String, String>(); for (Map.Entry<Object, Object> entry : props.entrySet()) { propertiesMap.put((String) entry.getKey(), (String) entry.getValue()); } return propertiesMap; }
From source file:ee.cyber.licensing.service.MailService.java
private static Properties getProperties() throws IOException { InputStream input = MailService.class.getClassLoader().getResourceAsStream("config.properties"); if (input == null) { throw new RuntimeException(); }//from w w w .ja v a2 s. co m Properties props = new Properties(System.getProperties()); props.load(input); input.close(); return props; }
From source file:jp.primecloud.auto.tool.management.util.ManagementConfigLoader.java
protected static void loadProperties(String propertyPath) throws Exception { InputStream input = ManagementConfigLoader.class.getClassLoader().getResourceAsStream(propertyPath); if (input == null) { throw new RuntimeException(MessageUtils.format("ConfigFile '{0}' is not found.", propertyPath)); }// w w w. j a va2s. co m Properties properties = ConfigHolder.getProperties(); if (properties == null) { properties = new Properties(); } try { properties.load(input); ConfigHolder.setProperties(properties); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.omertron.thetvdbapiv2.TestLogger.java
/** * Load properties from a file/*ww w . j ava 2 s. c o m*/ * * @param props * @param propertyFile */ public static void loadProperties(Properties props, File propertyFile) { InputStream is = null; try { is = new FileInputStream(propertyFile); props.load(is); } catch (IOException ex) { LOG.warn("Failed to load properties file", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { LOG.warn("Failed to close properties file", ex); } } } }
From source file:de.kasoki.jfeedly.model.FeedlyConnection.java
/** Restores an existing connection */ public static FeedlyConnection restoreConnection(String connectionFilePath) { Properties prop = new Properties(); try {/*from w w w. j a v a 2 s . c o m*/ //load connection properties file prop.load(new FileInputStream(connectionFilePath)); HashMap<String, String> map = createConnectionHashMap(prop.getProperty("access_token"), prop.getProperty("refresh_token"), prop.getProperty("plan"), prop.getProperty("token_type"), prop.getProperty("id"), prop.getProperty("expire_date"), connectionFilePath); return new FeedlyConnection(map); } catch (IOException ex) { ex.printStackTrace(); } return null; }
From source file:com.massabot.codesender.utils.SettingsFactory.java
/** * Convert legacy property file to JSON, move files from top level setting directory to UGS * settings directory./*from w w w.j av a 2 s . c o m*/ */ private static void migrateOldSettings() { File newSettingsDir = getSettingsDirectory(); File oldSettingDir = newSettingsDir.getParentFile(); File oldPropertyFile = new File(oldSettingDir, PROPERTIES_FILENAME); File oldJsonFile = new File(oldSettingDir, JSON_FILENAME); // Convert property file in old location to json file in new location. if (oldPropertyFile.exists()) { try { Settings out = new Settings(); // logger.log(Level.INFO, "{0}: {1}", new // Object[]{Localization.getString("settings.log.location"), settingsFile}); logger.log(Level.INFO, "Log location: {0}", oldPropertyFile.getAbsolutePath()); Properties properties = new Properties(); properties.load(new FileInputStream(oldPropertyFile)); out.setLastOpenedFilename(properties.getProperty("last.dir", System.getProperty(USER_HOME))); out.setPort(properties.getProperty("port", "")); out.setPortRate(properties.getProperty("port.rate", "9600")); out.setManualModeEnabled(Boolean.valueOf(properties.getProperty("manualMode.enabled", FALSE))); out.setManualModeStepSize(Double.valueOf(properties.getProperty("manualMode.stepsize", "1"))); out.setScrollWindowEnabled(Boolean.valueOf(properties.getProperty("scrollWindow.enabled", "true"))); out.setVerboseOutputEnabled( Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE))); out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL")); out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE))); out.setStatusUpdatesEnabled( Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true"))); out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200"))); out.setDisplayStateColor(Boolean.valueOf(properties.getProperty("displayStateColor", "true"))); out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;")); out.updateMacro(2, null, null, properties.getProperty("customGcode2", "G0 G91 X10;G0 G91 Y10;")); out.updateMacro(3, null, null, properties.getProperty("customGcode3", "")); out.updateMacro(4, null, null, properties.getProperty("customGcode4", "")); out.updateMacro(5, null, null, properties.getProperty("customGcode5", "")); out.setLanguage(properties.getProperty("language", "en_US")); saveSettings(out); // Delete the old settings file if it exists. oldPropertyFile.delete(); } catch (IOException ex) { Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex); } } // Move old json file from old location to new location. else if (oldJsonFile.exists()) { try { // If the new file doesn't exist, move the old one. if (!getSettingsFile().exists()) { FileUtils.moveFile(oldJsonFile, getSettingsFile()); } // Delete the old settings file if it exists. oldJsonFile.delete(); } catch (IOException ex) { Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.asakusafw.cleaner.log.LogMessageLoader.java
/** * ??/*from w w w . jav a2 s. c om*/ * ???????? * <p> * ????.properties????? * ??????????? * </p> * @param manager ? * @throws IOException ????? */ static void loadFile(LogMessageManager manager) throws IOException { // ? InputStream in = null; Properties props = new Properties(); try { in = LogMessageLoader.class.getClassLoader().getResourceAsStream(Constants.LOG_MESSAGE_FILE); props.load(in); Enumeration<?> keys = props.propertyNames(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.endsWith(LEVEL_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, LEVEL_KEY_END); manager.putLevel(messageId, props.getProperty(key)); } else if (key.endsWith(TEMPLATE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, TEMPLATE_KEY_END); manager.putTemplate(messageId, props.getProperty(key)); } else if (key.endsWith(SIZE_KEY_END)) { String messageId = LogMessageLoader.getMessageId(key, SIZE_KEY_END); String sizeStr = props.getProperty(key); if (NumberUtils.isNumber(sizeStr)) { manager.putSize(messageId, Integer.valueOf(sizeStr)); } } } } catch (IOException ex) { throw new IOException( "??????????" + Constants.LOG_MESSAGE_FILE, ex); } finally { IOUtils.closeQuietly(in); } }
From source file:de.mfo.jsurf.grid.RotationGrid.java
public static void loadFromString(String s) throws Exception { Properties props = new Properties(); props.load(new ByteArrayInputStream(s.getBytes())); loadFromProperties(props);/*w w w . j a va 2 s. c o m*/ }