List of usage examples for java.util Properties Properties
public Properties()
From source file:Main.java
/** * Stores the properties using {@link Properties#store(OutputStream, String)} on the given <code>stream</code>. * @param properties The properties to store * @param stream The stream to store to/*w w w . j a va2s . co m*/ * @param comment The comment to use * @throws IOException */ public static void storeProperties(Map<String, String> properties, OutputStream stream, String comment) throws IOException { Properties props = new Properties(); props.putAll(properties); props.store(stream, comment); }
From source file:de.marza.firstspirit.modules.logging.fsm.FsmIT.java
/** * Sets up before.// ww w . jav a 2s . c o m * * @throws Exception the exception */ @BeforeClass public static void setUpBefore() throws Exception { pomProperties = new Properties(); final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); final InputStream inputStream = systemClassLoader.getResourceAsStream("moduleTest.properties"); pomProperties.load(inputStream); }
From source file:com.impetus.benchmark.utils.MailUtils.java
public static void sendMail(Map<String, Double> delta, String operationType, String dataStore) { String host = "mail1.impetus.co.in"; int port = 465; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); // props.put("mail.smtp.port", "465"); props.put("mail.smtp.host", host); JavaMailSenderImpl emailSender = new JavaMailSenderImpl(); emailSender.setHost(host);/*from www . j ava 2 s. co m*/ // emailSender.setPort(port); emailSender.setUsername("amresh.singh@impetus.co.in"); emailSender.setPassword("dragon@131"); emailSender.setJavaMailProperties(props); SimpleMailMessage mail = new SimpleMailMessage(); mail.setTo(new String[] { /*"vivek.mishra@impetus.co.in",*/ "amresh.singh@impetus.co.in", /*"kuldeep.mishra@impetus.co.in"*//*, "vivek.shrivastava@impetus.co.in"*/ }); mail.setFrom("amresh.singh@impetus.co.in"); mail.setReplyTo("amresh.singh@impetus.co.in"); // mail.se if (operationType.equalsIgnoreCase("load")) { operationType = "write"; } else if (operationType.equalsIgnoreCase("t")) { operationType = "read"; } mail.setSubject(operationType + " kundera-" + dataStore + "-performance Delta"); String mailBody = null; for (String key : delta.keySet()) { if (mailBody == null) { mailBody = key + " Performance Delta ==> " + delta.get(key) + " \n"; } else { mailBody = mailBody + key + " Performance Delta ==> " + delta.get(key) + " \n"; } } mail.setText(mailBody); emailSender.send(mail); }
From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java
public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException { CobarAdapter cAdapter = new CobarAdapter(); Properties prop = new Properties(); prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties")); BasicDataSource ds = new BasicDataSource(); String user = prop.getProperty(cobarNodeName + ".user").trim(); String password = prop.getProperty(cobarNodeName + ".password").trim(); String ip = prop.getProperty(cobarNodeName + ".ip").trim(); int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim()); int maxActive = -1; int minIdle = 0; long timeBetweenEvictionRunsMillis = 10 * 60 * 1000; int numTestsPerEvictionRun = Integer.MAX_VALUE; long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; ds.setUsername(user);// www . j av a2 s . c o m ds.setPassword(password); ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/") .toString()); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setMaxActive(maxActive); ds.setMinIdle(minIdle); ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun); ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); cAdapter.setDataSource(ds); return cAdapter; }
From source file:Main.java
/** * This isn't what the RI does. The RI doesn't have hard-coded defaults, so * supplying your own "content.types.user.table" means you don't get any of * the built-ins, and the built-ins come from * "$JAVA_HOME/lib/content-types.properties". *//*from w w w . ja va 2s . c o m*/ private static void applyOverrides() { // Get the appropriate InputStream to read overrides from, if any. InputStream stream = getContentTypesPropertiesStream(); if (stream == null) { return; } try { try { // Read the properties file... Properties overrides = new Properties(); overrides.load(stream); // And translate its mapping to ours... for (Map.Entry<Object, Object> entry : overrides.entrySet()) { String extension = (String) entry.getKey(); String mimeType = (String) entry.getValue(); add(mimeType, extension); } } finally { stream.close(); } } catch (IOException ignored) { } }
From source file:com.qpark.eip.core.sftp.SftpSessionFactoryProvider.java
/** * Get the {@link DefaultSftpSessionFactory} according to the * {@link ConnectionDetails}.//w w w .j a v a2 s .c o m * * @param connectionDetails * the {@link ConnectionDetails}. * @return the {@link DefaultSftpSessionFactory}. */ public static DefaultSftpSessionFactory getSessionFactory(final ConnectionDetails connectionDetails) { Properties sessionConfig = new Properties(); sessionConfig.setProperty("compression.s2c", "zlib@openssh.com,none"); sessionConfig.setProperty("compression.c2s", "zlib@openssh.com,none"); sessionConfig.setProperty("compression_level", "9"); DefaultSftpSessionFactory sessionFactory = new DefaultSftpSessionFactory(); sessionFactory.setHost(connectionDetails.getHostName()); sessionFactory.setPort(connectionDetails.getPort()); sessionFactory.setUser(connectionDetails.getUserName()); sessionFactory.setPassword(new String(connectionDetails.getPassword())); sessionFactory.setSessionConfig(sessionConfig); return sessionFactory; }
From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java
public static synchronized LookupDataSource getDataSource() throws CacheRefreshException { if (dataSource == null) { try {/*from w w w . ja v a 2s . c o m*/ Properties config = new Properties(); config.load(new FileInputStream("lookup-connection.properties")); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(config.getProperty("lookup.class")); ds.setUrl(config.getProperty("lookup.url")); ds.setUsername(config.getProperty("lookup.username")); ds.setPassword(config.getProperty("lookup.password")); ds.setDefaultReadOnly(false); dataSource = new JdbcLookupDataSource(ds); } catch (FileNotFoundException e) { throw new CacheRefreshException("Could not find lookup-connection.properties file", e); } catch (IOException e) { throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file", e); } catch (RuntimeException e) { throw new CacheRefreshException("Could not create data source", e); } } return dataSource; }
From source file:controllers.FormsController.java
private static Properties getPropertyFile() { Properties properties = new Properties(); InputStream stream = Play.application().classloader().getResourceAsStream("forms_en.properties"); try {//from www. ja v a2 s . c o m properties.load(stream); stream.close(); return properties; } catch (FileNotFoundException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); return null; } catch (IOException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { stream.close(); } catch (IOException ex) { Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:Main.java
public static boolean savePreferencesInExternal(Context ctx, SharedPreferences pref) { Properties propfile = new Properties(); Map<String, ?> keymap = pref.getAll(); Iterator<String> keyit = keymap.keySet().iterator(); Log.d("External", "Saving prefrences to external Storages"); while (keyit.hasNext()) { String key = keyit.next(); propfile.put(key, keymap.get(key)); }/* w ww.ja va 2s . co m*/ if (isExternalStorageAvailableforWriting() == true) { try { propfile.storeToXML(new FileOutputStream(new File(ctx.getExternalFilesDir(null), "install_info")), null); } catch (Exception e) { e.printStackTrace(); } Log.d("External", "Saved prefrences to external "); return true; } else { Log.d("External", "Failed to Save prefrences for external "); return false; } }
From source file:com.github.yongchristophertang.config.PropertyHandler.java
public static void loadProperties(Class<?> testClass, Object[] testInstances) { Properties prop = new Properties(); PropertyConfig[] propertyConfigs = getAnnotations(null, testClass, PropertyConfig.class); Lists.newArrayList(propertyConfigs).stream().filter(pc -> pc.value().endsWith(".properties")) .forEach(pc -> {// ww w . java 2 s . com try { prop.load(testClass.getClassLoader().getResourceAsStream(pc.value())); } catch (IOException e) { e.printStackTrace(); } }); Field[] fields = testClass.getFields(); Lists.newArrayList(fields).stream().filter(f -> f.isAnnotationPresent(Property.class)) .filter(f -> f.getType() == String.class).peek(f -> f.setAccessible(true)).forEach(f -> { for (Object instance : testInstances) { try { f.set(instance, prop.getProperty(f.getAnnotation(Property.class).value())); } catch (IllegalAccessException e) { e.printStackTrace(); } } }); }