List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:com.gnizr.core.delicious.DeliciousImportApp.java
/** * @param args//w w w . j a v a 2s .c o m */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Missing required arguments."); System.exit(1); } Properties prpt = new Properties(); prpt.load(new FileInputStream(args[0])); String dbdrv = prpt.getProperty("gnizr.db.driver"); String dbUrl = prpt.getProperty("gnizr.db.url"); String dbUser = prpt.getProperty("gnizr.db.username"); String dbPass = prpt.getProperty("gnizr.db.password"); String gnizrUser = prpt.getProperty("gnizr.import.user"); String gnizrPassword = prpt.getProperty("gnizr.import.password"); String gnizrEmail = prpt.getProperty("gnizr.import.email"); String gnizrFullname = prpt.getProperty("gnizr.import.fullname"); String deliUser = prpt.getProperty("gnizr.import.delicious.user"); String deliPassword = prpt.getProperty("gnizr.import.delicious.password"); BasicDataSource datasource = new BasicDataSource(); datasource.setDriverClassName(dbdrv); datasource.setUrl(dbUrl); datasource.setUsername(dbUser); datasource.setPassword(dbPass); GnizrDao gnizrDao = GnizrDao.getInstance(datasource); UserManager userManager = new UserManager(gnizrDao); BookmarkManager bookmarkManager = new BookmarkManager(gnizrDao); FolderManager folderManager = new FolderManager(gnizrDao); User gUser = new User(); gUser.setUsername(gnizrUser); gUser.setPassword(gnizrPassword); gUser.setFullname(gnizrFullname); gUser.setEmail(gnizrEmail); gUser.setAccountStatus(AccountStatus.ACTIVE); gUser.setCreatedOn(GnizrDaoUtil.getNow()); DeliciousImport deliciousImport = new DeliciousImport(deliUser, deliPassword, gUser, userManager, bookmarkManager, folderManager, true); ImportStatus status = deliciousImport.doImport(); System.out.println("Del.icio.us Import Status: "); System.out.println("- total number: " + status.getTotalNumber()); System.out.println("- number added: " + status.getNumberAdded()); System.out.println("- number updated: " + status.getNumberUpdated()); System.out.println("- number failed: " + status.getNumberError()); }
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.dfs.user.test.Retrieve.java
/** * Retrieve application will be started with the main() of the {@link Retrieve}. * //from w ww.ja va 2s.c om * @param args the parameter which is passed to the main() * @throws IOException * @throws FileNotFoundException * @throws IOException */ public static void main(String args[]) throws IOException { Properties prop = new Properties(); prop.load(new FileInputStream("server.properties")); Retrieve ret = new Retrieve(); ret.fileNameAnalyzer(prop.getProperty("retrieve.fileName")); ApplicationContext context = new ClassPathXmlApplicationContext("net\\dfs\\user\\test\\spring-user.xml"); RetrievalConnectionHandler retrieve = (RetrievalConnectionHandler) context.getBean("retrieve"); retrieve.retrieveFile(fileName, extention, InetAddress.getLocalHost().getHostAddress()); log.debug("The File " + fileName + extention + " Request from the Server"); }
From source file:com.sun.labs.aura.grid.ec2.Ec2Sample.java
public static void main(String[] args) throws Exception { Properties props = new Properties(); props.load(Ec2Sample.class.getResourceAsStream("aws.properties")); Jec2 ec2 = new Jec2(props.getProperty("aws.accessId"), props.getProperty("aws.secretKey")); List<String> params = new ArrayList<String>(); List<ImageDescription> images = ec2.describeImages(params); System.out.println(String.format("%d available images", images.size())); for (ImageDescription img : images) { if (img.getImageState().equals("available")) { System.out.println(img.getImageId() + "\t" + img.getImageLocation() + "\t" + img.getImageOwnerId()); }// ww w . jav a 2 s . c om } // describe instances params = new ArrayList<String>(); List<ReservationDescription> instances = ec2.describeInstances(params); System.out.println(String.format("%d instances", instances.size())); String instanceId = null; for (ReservationDescription res : instances) { System.out.println(res.getOwner() + "\t" + res.getReservationId()); if (res.getInstances() != null) { for (Instance inst : res.getInstances()) { System.out.println("\t" + inst.getImageId() + "\t" + inst.getDnsName() + "\t" + inst.getState() + "\t" + inst.getKeyName()); instanceId = inst.getInstanceId(); } } } // test console output if (instanceId != null) { ConsoleOutput consOutput = ec2.getConsoleOutput(instanceId); System.out.println("Console Output:"); System.out.println(consOutput.getOutput()); } // show keypairs List<KeyPairInfo> info = ec2.describeKeyPairs(new String[] {}); System.out.println("keypair list"); for (KeyPairInfo i : info) { System.out.println("keypair : " + i.getKeyName() + ", " + i.getKeyFingerprint()); } }
From source file:dhtaccess.tools.Remove.java
public static void main(String[] args) { int ttl = 3600; // parse properties Properties prop = System.getProperties(); String gateway = prop.getProperty("dhtaccess.gateway"); if (gateway == null || gateway.length() <= 0) { gateway = DEFAULT_GATEWAY;/*from w w w .java 2 s . c om*/ } // parse options Options options = new Options(); options.addOption("h", "help", false, "print help"); options.addOption("g", "gateway", true, "gateway URI, list at http://opendht.org/servers.txt"); options.addOption("t", "ttl", true, "how long (in seconds) to store the value"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println("There is an invalid option."); e.printStackTrace(); System.exit(1); } String optVal; if (cmd.hasOption('h')) { usage(COMMAND); System.exit(1); } optVal = cmd.getOptionValue('g'); if (optVal != null) { gateway = optVal; } optVal = cmd.getOptionValue('t'); if (optVal != null) { ttl = Integer.parseInt(optVal); } args = cmd.getArgs(); // parse arguments if (args.length < 3) { usage(COMMAND); System.exit(1); } byte[] key = null, value = null, secret = null; try { key = args[0].getBytes(ENCODE); value = args[1].getBytes(ENCODE); secret = args[2].getBytes(ENCODE); } catch (UnsupportedEncodingException e1) { // NOTREACHED } // prepare for RPC DHTAccessor accessor = null; try { accessor = new DHTAccessor(gateway); } catch (MalformedURLException e) { e.printStackTrace(); System.exit(1); } // RPC int res = accessor.remove(key, value, ttl, secret); String resultString; switch (res) { case 0: resultString = "Success"; break; case 1: resultString = "Capacity"; break; case 2: resultString = "Again"; break; default: resultString = "???"; } System.out.println(resultString); }
From source file:com.moreopen.config.center.ConfigCenterLauncher.java
public static void main(String[] args) throws Exception { final String PROFILE_NAME = "/app.properties"; Properties properties = PropertiesLoaderUtils .loadProperties(new UrlResource(ConfigCenterLauncher.class.getResource(PROFILE_NAME))); int port = Integer.parseInt(properties.getProperty("webserver.port")); if (port == 0) { logger.error("property: config.webserver.port not found, please check " + PROFILE_NAME); return;// w ww .j av a 2s . co m } // launch the monitor console server new ConfigCenterLauncher(port).run(); server.join(); }
From source file:MainClass.java
public static void main(String args[]) { Properties capitals = new Properties(); capitals.put("K1", "V1"); capitals.put("K2", "V2"); Set states = capitals.keySet(); for (Object name : states) System.out.println("The value of " + name + " is " + capitals.getProperty((String) name) + "."); }
From source file:ImageStringToBlob.java
public static void main(String[] args) { Connection conn = null;//from w ww.j av a 2s.co m if (args.length != 1) { System.out.println("Missing argument: full path to <oscar.properties>"); return; } try { FileInputStream fin = new FileInputStream(args[0]); Properties prop = new Properties(); prop.load(fin); String driver = prop.getProperty("db_driver"); String uri = prop.getProperty("db_uri"); String db = prop.getProperty("db_name"); String username = prop.getProperty("db_username"); String password = prop.getProperty("db_password"); Class.forName(driver); conn = DriverManager.getConnection(uri + db, username, password); conn.setAutoCommit(true); // no transactions /* * select all records ids with image_data not null and contents is null * for each id fetch record * migrate data from image_data to contents */ String sql = "select image_id from client_image where image_data is not null and contents is null"; PreparedStatement pst = conn.prepareStatement(sql); ResultSet rs = pst.executeQuery(); List<Long> ids = new ArrayList<Long>(); while (rs.next()) { ids.add(rs.getLong("image_id")); } rs.close(); sql = "select image_data from client_image where image_id = ?"; pst = conn.prepareStatement(sql); System.out.println("Migrating image data for " + ids.size() + " images..."); for (Long id : ids) { pst.setLong(1, id); ResultSet imagesRS = pst.executeQuery(); while (imagesRS.next()) { String dataString = imagesRS.getString("image_data"); Blob dataBlob = fromStringToBlob(dataString); if (writeBlobToDb(conn, id, dataBlob) == 1) { System.out.println("Image data migrated for image_id: " + id); } } imagesRS.close(); } System.out.println("Migration completed."); } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.semsaas.utils.anyurl.App.java
public static void main(String[] rawArgs) throws Exception { Properties props = new Properties(); String args[] = processOption(rawArgs, props); String outputFile = props.getProperty("output"); OutputStream os = outputFile == null ? System.out : new FileOutputStream(outputFile); final org.apache.camel.spring.Main main = new org.apache.camel.spring.Main(); main.setApplicationContextUri("classpath:application.xml"); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { main.stop();// w w w.j a v a2 s. c om } catch (Exception e) { } } }); if (args.length > 0) { main.start(); if (main.isStarted()) { CamelContext camelContext = main.getCamelContexts().get(0); String target = rewriteEndpoint(args[0]); boolean producerBased = checkProducerBased(target); InputStream is = null; if (producerBased) { ProducerTemplate producer = camelContext.createProducerTemplate(); is = producer.requestBody(target, null, InputStream.class); } else { ConsumerTemplate consumer = camelContext.createConsumerTemplate(); is = consumer.receiveBody(target, InputStream.class); } IOUtils.copy(is, os); main.stop(); } else { System.err.println("Couldn't trigger jobs, camel wasn't started"); } } else { logger.info("No triggers. Running indefintely"); } }
From source file:com.yahoo.labs.samoa.topology.impl.StormTopologySubmitter.java
public static void main(String[] args) throws IOException { Properties props = StormSamoaUtils.getProperties(); String uploadedJarLocation = props.getProperty(StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); if (uploadedJarLocation == null) { logger.error("Invalid properties file. It must have key {}", StormJarSubmitter.UPLOADED_JAR_LOCATION_KEY); return;/*from w w w .j av a 2 s .co m*/ } List<String> tmpArgs = new ArrayList<String>(Arrays.asList(args)); int numWorkers = StormSamoaUtils.numWorkers(tmpArgs); args = tmpArgs.toArray(new String[0]); StormTopology stormTopo = StormSamoaUtils.argsToTopology(args); Config conf = new Config(); conf.putAll(Utils.readStormConfig()); conf.putAll(Utils.readCommandLineOpts()); conf.setDebug(false); conf.setNumWorkers(numWorkers); String profilerOption = props.getProperty(StormTopologySubmitter.YJP_OPTIONS_KEY); if (profilerOption != null) { String topoWorkerChildOpts = (String) conf.get(Config.TOPOLOGY_WORKER_CHILDOPTS); StringBuilder optionBuilder = new StringBuilder(); if (topoWorkerChildOpts != null) { optionBuilder.append(topoWorkerChildOpts); optionBuilder.append(' '); } optionBuilder.append(profilerOption); conf.put(Config.TOPOLOGY_WORKER_CHILDOPTS, optionBuilder.toString()); } Map<String, Object> myConfigMap = new HashMap<String, Object>(conf); StringWriter out = new StringWriter(); try { JSONValue.writeJSONString(myConfigMap, out); } catch (IOException e) { System.out.println("Error in writing JSONString"); e.printStackTrace(); return; } Config config = new Config(); config.putAll(Utils.readStormConfig()); String nimbusHost = (String) config.get(Config.NIMBUS_HOST); NimbusClient nc = new NimbusClient(nimbusHost); String topologyName = stormTopo.getTopologyName(); try { System.out.println("Submitting topology with name: " + topologyName); nc.getClient().submitTopology(topologyName, uploadedJarLocation, out.toString(), stormTopo.getStormBuilder().createTopology()); System.out.println(topologyName + " is successfully submitted"); } catch (AlreadyAliveException aae) { System.out.println("Fail to submit " + topologyName + "\nError message: " + aae.get_msg()); } catch (InvalidTopologyException ite) { System.out.println("Invalid topology for " + topologyName); ite.printStackTrace(); } catch (TException te) { System.out.println("Texception for " + topologyName); te.printStackTrace(); } }