List of usage examples for java.util Properties Properties
public Properties()
From source file:com.joseflavio.unhadegato.Concentrador.java
/** * @param args [0] = Diretrio de configuraes. *//*from w ww . j a v a2s . co m*/ public static void main(String[] args) { log.info(Util.getMensagem("unhadegato.iniciando")); try { /***********************/ if (args.length > 0) { if (!args[0].isEmpty()) { configuracao = new File(args[0]); if (!configuracao.isDirectory()) { String msg = Util.getMensagem("unhadegato.diretorio.incorreto"); System.out.println(msg); log.error(msg); System.exit(1); } } } if (configuracao == null) { configuracao = new File(System.getProperty("user.home") + File.separator + "unhadegato"); configuracao.mkdirs(); } log.info(Util.getMensagem("unhadegato.diretorio.endereco", configuracao.getAbsolutePath())); /***********************/ File confGeralArq = new File(configuracao, "unhadegato.conf"); if (!confGeralArq.exists()) { try (InputStream is = Concentrador.class.getResourceAsStream("/unhadegato.conf"); OutputStream os = new FileOutputStream(confGeralArq);) { IOUtils.copy(is, os); } } Properties confGeral = new Properties(); try (FileInputStream fis = new FileInputStream(confGeralArq)) { confGeral.load(fis); } String prop_porta = confGeral.getProperty("porta"); String prop_porta_segura = confGeral.getProperty("porta.segura"); String prop_seg_pri = confGeral.getProperty("seguranca.privada"); String prop_seg_pri_senha = confGeral.getProperty("seguranca.privada.senha"); String prop_seg_pri_tipo = confGeral.getProperty("seguranca.privada.tipo"); String prop_seg_pub = confGeral.getProperty("seguranca.publica"); String prop_seg_pub_senha = confGeral.getProperty("seguranca.publica.senha"); String prop_seg_pub_tipo = confGeral.getProperty("seguranca.publica.tipo"); if (StringUtil.tamanho(prop_porta) == 0) prop_porta = "8885"; if (StringUtil.tamanho(prop_porta_segura) == 0) prop_porta_segura = "8886"; if (StringUtil.tamanho(prop_seg_pri) == 0) prop_seg_pri = "servidor.jks"; if (StringUtil.tamanho(prop_seg_pri_senha) == 0) prop_seg_pri_senha = "123456"; if (StringUtil.tamanho(prop_seg_pri_tipo) == 0) prop_seg_pri_tipo = "JKS"; if (StringUtil.tamanho(prop_seg_pub) == 0) prop_seg_pub = "cliente.jks"; if (StringUtil.tamanho(prop_seg_pub_senha) == 0) prop_seg_pub_senha = "123456"; if (StringUtil.tamanho(prop_seg_pub_tipo) == 0) prop_seg_pub_tipo = "JKS"; /***********************/ File seg_pri = new File(prop_seg_pri); if (!seg_pri.isAbsolute()) seg_pri = new File(configuracao.getAbsolutePath() + File.separator + prop_seg_pri); if (seg_pri.exists()) { System.setProperty("javax.net.ssl.keyStore", seg_pri.getAbsolutePath()); System.setProperty("javax.net.ssl.keyStorePassword", prop_seg_pri_senha); System.setProperty("javax.net.ssl.keyStoreType", prop_seg_pri_tipo); } File seg_pub = new File(prop_seg_pub); if (!seg_pub.isAbsolute()) seg_pub = new File(configuracao.getAbsolutePath() + File.separator + prop_seg_pub); if (seg_pub.exists()) { System.setProperty("javax.net.ssl.trustStore", seg_pub.getAbsolutePath()); System.setProperty("javax.net.ssl.trustStorePassword", prop_seg_pub_senha); System.setProperty("javax.net.ssl.trustStoreType", prop_seg_pub_tipo); } /***********************/ new Thread() { File arquivo = new File(configuracao, "copaibas.conf"); long ultimaData = -1; @Override public void run() { while (true) { long data = arquivo.lastModified(); if (data > ultimaData) { executarCopaibas(arquivo); ultimaData = data; } try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { return; } } } }.start(); /***********************/ log.info(Util.getMensagem("unhadegato.conexao.esperando")); log.info(Util.getMensagem("copaiba.porta.normal.abrindo", prop_porta)); Portal portal1 = new Portal(new SocketServidor(Integer.parseInt(prop_porta), false, true)); log.info(Util.getMensagem("copaiba.porta.segura.abrindo", prop_porta_segura)); Portal portal2 = new Portal(new SocketServidor(Integer.parseInt(prop_porta_segura), true, true)); portal1.start(); portal2.start(); portal1.join(); /***********************/ } catch (Exception e) { log.error(e.getMessage(), e); } finally { for (CopaibaGerenciador gerenciador : gerenciadores.values()) gerenciador.encerrar(); gerenciadores.clear(); gerenciadores = null; } }
From source file:Main.java
/** * return a properties with the values passed as params * /*from w w w .jav a 2 s . c o m*/ * @param strKeys the keys to insert into the pr * @param strValues the values to insert into the pr * @return */ public static Properties loadProperties(String[] strKeys, String[] strValues) { // checks the params if (strKeys == null || strValues == null) return null; // inits the PR Properties pr = new Properties(); // cycles on keys for (int j = 0; j < strKeys.length; j++) { // insert the j-th key into the properties pr.setProperty(strKeys[j], strValues[j]); } // and returns it return pr; }
From source file:com.enonic.cms.framework.util.PropertiesUtil.java
/** * Return a subset of properties.//from w ww.j a va 2 s .c om */ public static Properties getSubSet(final Properties props, final String base) { Properties sub = new Properties(); for (Map.Entry entry : props.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (key.startsWith(base)) { sub.setProperty(key.substring(base.length()), value); } } return sub; }
From source file:ParseNonXML.java
public static Properties buildProperties() { Properties props = new Properties(); for (int i = 0; i < 10; i++) props.setProperty("key" + i, "value" + i); return props; }
From source file:Main.java
public static void loadHashMapData() throws IOException { HashMap<String, String> hashMap = new HashMap<String, String>(); Properties properties = new Properties(); File file = new File(HASHMAPFILEPATH); if (file.exists()) { properties.load(new FileInputStream(HASHMAPFILEPATH)); for (String key : properties.stringPropertyNames()) { hashMap.put(key, properties.getProperty(key)); GPSDataMap = hashMap;/*from w w w . ja v a 2s .co m*/ } } else { file.createNewFile(); } }
From source file:agency.Agency.java
private static DataSource prepareDataSource() throws SQLException, IOException { Properties myconf = new Properties(); myconf.load(Agency.class.getResourceAsStream("/myconf.properties")); BasicDataSource ds = new BasicDataSource(); ds.setUrl(myconf.getProperty("jdbc.url")); ds.setUsername(myconf.getProperty("jdbc.user")); ds.setPassword(myconf.getProperty("jdbc.password")); return ds;// w ww . j a va 2 s . c om }
From source file:Main.java
public static void getParam(String filename) { Properties props = new Properties(); File file = new File(filename); try {/*from w w w .ja va 2 s.c o m*/ props.load(new FileInputStream(file)); // String value = props.getProperty(key); driver = props.getProperty("driver"); url = props.getProperty("url"); dbUser = props.getProperty("dbUser"); dbPwd = props.getProperty("dbPwd"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
static Properties convertResourceBundleToProperties(ResourceBundle resource) { Properties properties = new Properties(); Enumeration<String> keys = resource.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, resource.getString(key)); }/*from ww w . j a va 2 s . c o m*/ return properties; }
From source file:fitnesse.FitNesseVersion.java
private static Properties getBuildProperties() { Properties buildProperties = new Properties(); InputStream propertyStream = null; Reader propertyReader = null; try {/*from ww w .ja v a 2 s .c o m*/ propertyStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("fitnesse/build.properties"); propertyReader = new InputStreamReader(propertyStream); buildProperties.load(propertyReader); } catch (NullPointerException e) { throw new RuntimeException( "Could not load build.properties from the classpath. Are you sure the jar is packaged correctly?", e); } catch (IOException e) { throw new RuntimeException( "Could not load build.properties from the classpath. Are you sure the jar is packaged correctly?", e); } finally { IOUtils.closeQuietly(propertyReader); IOUtils.closeQuietly(propertyStream); } return buildProperties; }
From source file:Main.java
/** * Reset all error flags to 0./*www . java 2s.c om*/ */ public static void resetErrorFlags() { Log.i(TAG, "Reset all error flags."); Properties prop = new Properties(); prop.put(ILLEGAL_STATE_ERROR, "0"); prop.put(ILLEGAL_ARGUMENT_ERROR, "0"); prop.put(INSTANTIATION_ERROR, "0"); saveConfig(prop); }