List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.jdom.util.PropertiesUtil.java
private static Properties readPropertiesFile(final InputStream is) throws IllegalArgumentException { Properties properties = new Properties(); try {/*from ww w . j a v a 2 s. c o m*/ properties.load(is); } catch (IOException e) { throw new IllegalArgumentException("Unable to read the properties file!", e); } finally { IOUtils.closeQuietly(is); } return properties; }
From source file:com.aliyun.oss.utils.ServiceSettings.java
/** * Load settings from the configuration file. * <p>//from www . j av a2 s .c o m * The configuration format: * oss.endpoint= * oss.accesskeyid= * oss.accesskeysecret= * proxy.host= * proxy.port= * </p> * @return */ public static ServiceSettings load() { ServiceSettings ss = new ServiceSettings(); InputStream is = null; try { is = new FileInputStream(SETTINGS_FILE_NAME); Properties pr = new Properties(); pr.load(is); ss.properties = pr; } catch (FileNotFoundException e) { log.warn("The settings file '" + SETTINGS_FILE_NAME + "' does not exist."); } catch (IOException e) { log.warn("Failed to load the settings from the file: " + SETTINGS_FILE_NAME); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return ss; }
From source file:com.baidu.qa.service.test.util.MysqlDatabaseManager.java
/** * ?mysql db??//from w ww . ja v a 2s. c o m * @param dbname * @return * @throws SQLException */ static public Connection getCon(String dbname) throws SQLException { String host = ""; String user = ""; String database = ""; String password = ""; String driverClass = ""; String useUnicode = ""; try { // ???? InputStream in = new BufferedInputStream( new FileInputStream(ServiceInterfaceCaseTest.CASEPATH + Constant.FILENAME_DB)); Properties Info = new Properties(); Info.load(in); host = Info.getProperty(dbname + "_DB_Host"); user = Info.getProperty(dbname + "_DB_User"); database = Info.getProperty(dbname + "_DB_DataBase"); password = Info.getProperty(dbname + "_DB_Password"); driverClass = Info.getProperty(dbname + "_DB_DriverClass"); useUnicode = Info.getProperty(dbname + "_DB_UseUnicode"); } catch (Exception e) { log.error("[mysql configure file for" + dbname + "error]:", e); throw new AssertionError("[get mysql database config error from properties file]"); } if (host == null) { log.error("[load configure file for " + dbname + " error]:"); return null; } // String url = "jdbc:mysql://" + host.trim() + "/" + ((database != null) ? database.trim() : "") + "?useUnicode=" + ((useUnicode != null) ? useUnicode.trim() : "true&characterEncoding=gbk"); try { Class.forName(driverClass); } catch (ClassNotFoundException e) { log.error("[class not found]:", e); throw new AssertionError("[class not found]"); } Connection con = null; try { con = DriverManager.getConnection(url, user, password); } catch (SQLException a) { log.error("[mysql connection exception] ", a); throw new AssertionError("[mysql connection exception]"); } return con; }
From source file:it.geosolutions.geobatch.catalog.file.GeoBatchDataDirAwarePropertyOverrideConfigurer.java
/** * Tries to find the provided properties file and then returns its properties. * /*from w ww. ja v a2 s.c o m*/ * @param propertiesFile the {@link File} to load from. Must exists and be readable. * @throws IOException in case something bad happens trying to read the proeprties from the file. * */ protected static Properties loadProperties(final File propertiesFile) throws IOException { // checks on provided file if (!(propertiesFile != null && propertiesFile.exists() && propertiesFile.isFile() && propertiesFile.canRead())) { return null; } // load the file InputStream is = null; try { is = new BufferedInputStream(new FileInputStream(propertiesFile)); final Properties properties = new Properties(); properties.load(is); return properties; } finally { // close if (is != null) { try { is.close(); } catch (Exception e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(e.getLocalizedMessage(), e); } } } } }
From source file:com.google.code.fqueue.util.Config.java
/** * ??/* ww w. j a va 2 s. c om*/ * * @param path * * @throws FileNotFoundException */ public static synchronized void iniSetting(String path) { File file; file = new File(path); FileInputStream in = null; try { in = new FileInputStream(file); Properties p = new Properties(); p.load(in); // ???Map Enumeration<?> item = p.propertyNames(); while (item.hasMoreElements()) { String key = (String) item.nextElement(); setting.put(key, p.getProperty(key)); } in.close(); } catch (FileNotFoundException e) { log.error("config file not found at" + file.getAbsolutePath()); throw new ConfigException("FileNotFoundException", e); } catch (IOException e) { log.error("config file not found at" + file.getAbsolutePath()); throw new ConfigException("IOException", e); } catch (Exception e) { throw new ConfigException("Exception", e); } }
From source file:Main.java
public static Properties loadPropertyInstance(String filePath, String fileName) { try {//from ww w .j a v a2s. com File d = new File(filePath); if (!d.exists()) { d.mkdirs(); } File f = new File(d, fileName); if (!f.exists()) { f.createNewFile(); } Properties p = new Properties(); InputStream is = new FileInputStream(f); p.load(is); is.close(); return p; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.xpfriend.fixture.runner.example.ExampleJob.java
/** * db.properties ?????/*from www . j a va 2s . c o m*/ * @return ? */ private static Properties getProperties() throws IOException { Properties props = new Properties(); InputStream is = ClassLoader.getSystemResourceAsStream("db.properties"); try { props.load(is); } finally { is.close(); } return props; }
From source file:com.jdom.util.properties.PropertiesUtil.java
public static Properties readPropertiesFile(final InputStream is) throws IllegalArgumentException { Properties properties = new Properties(); try {//from ww w . j a v a2 s . c o m properties.load(is); } catch (IOException e) { throw new IllegalArgumentException("Unable to read the properties file!", e); } finally { IOUtils.closeQuietly(is); } return properties; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.db.UserDAOImplTest.java
@BeforeClass public static void setupDatabase() throws Exception { InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties"); Properties testProperties = new Properties(); testProperties.load(inputStream); String host = testProperties.getProperty("db.host"); String port = testProperties.getProperty("db.port"); String user = testProperties.getProperty("db.user"); String password = testProperties.getProperty("db.password"); String driver = testProperties.getProperty("db.driver"); String schema = testProperties.getProperty("db.schema"); String url = "jdbc:mysql://" + host + ":" + port + "/" + schema; ds = new BasicDataSource(); ds.setDriverClassName(driver);//from w w w . ja v a2 s . c o m ds.setUsername(user); ds.setPassword(password); ds.setUrl(url); DBTestUtil.setBasicDataSource(ds); generateRandomUserData(); }
From source file:com.bluexml.tools.miscellaneous.Translate.java
protected static TreeMap<String, String> loadProperties(File input) throws FileNotFoundException, IOException { TreeMap<String, String> map = new TreeMap<String, String>(); Properties props = new Properties(); FileInputStream fin = new FileInputStream(input); props.load(fin); Enumeration<Object> keys = props.keys(); while (keys.hasMoreElements()) { String nextElement = (String) keys.nextElement(); String property = props.getProperty(nextElement); map.put(nextElement, property);/* w w w . ja v a2s .c o m*/ } return map; }