List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:TestDSLookUp.java
public static void main(String[] args) throws SQLException, NamingException { Context ctx = null;/* w w w . j av a 2s . c om*/ try { Properties prop = new Properties(); prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC"); ctx = new InitialContext(prop); } catch (NamingException ne) { System.err.println(ne.getMessage()); } DataSource ds = (DataSource) ctx.lookup("joe"); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery( "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual"); if (rset.next()) System.out.println(rset.getString(1)); rset.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); StringWriter sw = new StringWriter(); prop.setProperty("Chapter Count", "200"); prop.put("Tutorial Count", "1500"); prop.put("tutorial", "java2s.com"); // print the list System.out.println(prop);/*from ww w . ja va 2s . c om*/ // store the properties list in an output writer prop.store(sw, "Main"); System.out.println(sw.toString()); }
From source file:com.netflix.suro.client.example.SuroClient4Test.java
public static void main(String[] args) throws JsonProcessingException, InterruptedException { // ip num_of_messages message_size sleep num_of_iterations String ip = args[0];// ww w . j ava 2s . c o m int numMessages = Integer.parseInt(args[1]); int messageSize = Integer.parseInt(args[2]); int sleep = Integer.parseInt(args[3]); int numIterations = Integer.parseInt(args[4]); Properties props = new Properties(); props.setProperty(ClientConfig.LB_TYPE, "static"); props.setProperty(ClientConfig.LB_SERVER, ip); SuroClient client = new SuroClient(props); byte[] payload = createMessagePayload(messageSize); for (int n = 0; n < numIterations; ++n) { for (int i = 0; i < numMessages; ++i) { client.send(new Message(i % 2 == 0 ? "request_trace" : "nf_errors_log", payload)); } Thread.sleep(sleep); } client.shutdown(); }
From source file:ezbake.services.search.SSRServer.java
public static void main(String[] args) throws Exception { final String applicationName = "search-app";//cmd.getOptionValue('a'); final String listenPort = "13004";//cmd.getOptionValue('l'); final String zookeeperString = "localhost:2181";//cmd.getOptionValue('z'); Properties props = new EzConfiguration().getProperties(); props.setProperty(EzBakePropertyConstants.EZBAKE_APPLICATION_NAME, applicationName); props.setProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING, zookeeperString); SSRServiceHandler handler = new SSRServiceHandler(); handler.setConfigurationProperties(props); TServerTransport serverTransport = new TServerSocket(Integer.parseInt(listenPort)); TServer server = new TSimpleServer( new TServer.Args(serverTransport).processor(handler.getThriftProcessor())); System.out.println("Starting the SSR service..."); server.serve();/*from w w w. ja v a 2 s. c om*/ }
From source file:ConnectionPoolBasics.java
public static void main(String args[]) throws Exception { GenericObjectPool gPool = new GenericObjectPool(); /*Class.forName("com.mysql.jdbc.Driver"); //from w ww .j a v a 2s . c om DriverManagerConnectionFactory cf = new DriverManagerConnectionFactory( "jdbc:mysql://localhost/commons", "root", "");*/ Properties props = new Properties(); props.setProperty("Username", "root"); props.setProperty("Password", ""); ConnectionFactory cf = new DriverConnectionFactory(new com.mysql.jdbc.Driver(), "jdbc:mysql://localhost/commons", props); KeyedObjectPoolFactory kopf = new GenericKeyedObjectPoolFactory(null, 8); PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, gPool, kopf, null, false, true); for (int i = 0; i < 5; i++) { gPool.addObject(); } // PoolingDataSource pds = new PoolingDataSource(gPool); PoolingDriver pd = new PoolingDriver(); pd.registerPool("example", gPool); for (int i = 0; i < 5; i++) { gPool.addObject(); } Connection conn = java.sql.DriverManager.getConnection("jdbc:apache:commons:dbcp:example"); System.err.println("Connection: " + conn); //": Delegate: " + ((org.apache.commons.dbcp.PoolingConnection)conn).getDelegate()); // do some work with the connection PreparedStatement ps = conn.prepareStatement("Select * from customer where id = ?"); System.err.println("Active: " + gPool.getNumActive() + ", Idle: " + gPool.getNumIdle()); conn.close(); System.err.println("Active: " + gPool.getNumActive() + ", Idle: " + gPool.getNumIdle()); }
From source file:com.dataartisans.Consumer.java
public static void main(String[] args) throws Exception { // set up the execution environment final StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment(); final ParameterTool pt = ParameterTool.fromArgs(args); Properties props = new Properties(); props.setProperty(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_ACCESSKEYID, pt.get("accesskey")); props.setProperty(KinesisConfigConstants.CONFIG_AWS_CREDENTIALS_PROVIDER_BASIC_SECRETKEY, pt.get("secretkey")); props.setProperty(KinesisConfigConstants.CONFIG_AWS_REGION, "eu-central-1"); props.setProperty(KinesisConfigConstants.CONFIG_STREAM_INIT_POSITION_TYPE, pt.get("start", "TRIM_HORIZON")); FlinkKinesisConsumer<String> consumer = new FlinkKinesisConsumer<>(pt.getRequired("stream"), new SimpleStringSchema(), props); DataStream<String> jsonStream = see.addSource(consumer); jsonStream.flatMap(new ThroughputLogger(5_000L)).setParallelism(1); jsonStream.flatMap(new LatencyStat()); //jsonStream.print(); // execute program see.execute("Kinesis data consumer"); }
From source file:JDOCreateDataStore.java
public static void main(String[] args) throws IOException { Properties p = new Properties(); p.load(new FileInputStream("jdo.properties")); p.setProperty("com.sun.jdori.option.ConnectionCreate", "true"); PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(p); PersistenceManager pm = pmf.getPersistenceManager(); Transaction tx = pm.currentTransaction(); tx.begin();//from ww w .ja va 2 s. c om tx.commit(); }
From source file:dpfmanager.shell.core.util.VersionUtil.java
public static void main(String[] args) { String version = args[0];/*from w w w .j a v a 2 s . co m*/ String baseDir = args[1]; String issPath = baseDir + "/package/windows/DPF Manager.iss"; String rpmPath = baseDir + "/package/linux/DPFManager.old.spec"; String propOutput = baseDir + "/target/classes/version.properties"; try { // Windows iss File issFile = new File(issPath); String issContent = FileUtils.readFileToString(issFile); String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version); if (!newIssContent.isEmpty()) { FileUtils.writeStringToFile(issFile, newIssContent); System.out.println("New version information updated! (iss)"); } // RPM spec File rpmFile = new File(rpmPath); String rpmContent = FileUtils.readFileToString(rpmFile); String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version); if (!newRpmContent.isEmpty()) { FileUtils.writeStringToFile(rpmFile, newRpmContent); System.out.println("New version information updated! (spec)"); } // Java properties file OutputStream output = new FileOutputStream(propOutput); Properties prop = new Properties(); prop.setProperty("version", version); prop.store(output, "Version autoupdated"); output.close(); System.out.println("New version information updated! (properties)"); } catch (Exception e) { System.out.println("Exception ocurred, no version changed."); e.printStackTrace(); } }
From source file:com.dragoniade.encrypt.EncryptionHelper.java
public static void main(String[] args) { Properties p = new Properties(); p.setProperty("key", "mypassword"); System.out.println(p.getProperty("key")); EncryptionHelper.encrypt(p, "username", "key"); System.out.println(p.getProperty("key")); EncryptionHelper.decrypt(p, "username", "key"); System.out.println(p.getProperty("key")); }
From source file:net.prhin.mailman.MailMan.java
public static void main(String[] args) { Properties props = new Properties(); props.setProperty(resourceBundle.getString("mailman.mail.store"), resourceBundle.getString("mailman.protocol")); Session session = Session.getInstance(props); try {//from ww w .j a va 2 s . com Store store = session.getStore(); store.connect(resourceBundle.getString("mailman.host"), resourceBundle.getString("mailman.user"), resourceBundle.getString("mailman.password")); Folder inbox = store.getFolder(resourceBundle.getString("mailman.folder")); inbox.open(Folder.READ_ONLY); inbox.getUnreadMessageCount(); Message[] messages = inbox.getMessages(); for (int i = 0; i <= messages.length / 2; i++) { Message tmpMessage = messages[i]; Multipart multipart = (Multipart) tmpMessage.getContent(); System.out.println("Multipart count: " + multipart.getCount()); for (int j = 0; j < multipart.getCount(); j++) { BodyPart bodyPart = multipart.getBodyPart(j); if (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())) { if (bodyPart.getContent().getClass().equals(MimeMultipart.class)) { MimeMultipart mimeMultipart = (MimeMultipart) bodyPart.getContent(); for (int k = 0; k < mimeMultipart.getCount(); k++) { if (mimeMultipart.getBodyPart(k).getFileName() != null) { printFileContents(mimeMultipart.getBodyPart(k)); } } } } else { printFileContents(bodyPart); } } } inbox.close(false); store.close(); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }