List of usage examples for java.util Properties load
public synchronized void load(InputStream inStream) throws IOException
From source file:com.cloud.test.utils.SubmitCert.java
public static void main(String[] args) { // Parameters List<String> argsList = Arrays.asList(args); Iterator<String> iter = argsList.iterator(); while (iter.hasNext()) { String arg = iter.next(); if (arg.equals("-c")) { certFileName = iter.next();// www.j av a2 s .c o m } if (arg.equals("-s")) { secretKey = iter.next(); } if (arg.equals("-a")) { apiKey = iter.next(); } if (arg.equals("-action")) { url = "Action=" + iter.next(); } } Properties prop = new Properties(); try { prop.load(new FileInputStream("conf/tool.properties")); } catch (IOException ex) { s_logger.error("Error reading from conf/tool.properties", ex); System.exit(2); } host = prop.getProperty("host"); port = prop.getProperty("port"); if (url.equals("Action=SetCertificate") && certFileName == null) { s_logger.error("Please set path to certificate (including file name) with -c option"); System.exit(1); } if (secretKey == null) { s_logger.error("Please set secretkey with -s option"); System.exit(1); } if (apiKey == null) { s_logger.error("Please set apikey with -a option"); System.exit(1); } if (host == null) { s_logger.error("Please set host in tool.properties file"); System.exit(1); } if (port == null) { s_logger.error("Please set port in tool.properties file"); System.exit(1); } TreeMap<String, String> param = new TreeMap<String, String>(); String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint") + "\n"; String temp = ""; if (certFileName != null) { cert = readCert(certFileName); param.put("cert", cert); } param.put("AWSAccessKeyId", apiKey); param.put("Expires", prop.getProperty("expires")); param.put("SignatureMethod", prop.getProperty("signaturemethod")); param.put("SignatureVersion", "2"); param.put("Version", prop.getProperty("version")); StringTokenizer str1 = new StringTokenizer(url, "&"); while (str1.hasMoreTokens()) { String newEl = str1.nextToken(); StringTokenizer str2 = new StringTokenizer(newEl, "="); String name = str2.nextToken(); String value = str2.nextToken(); param.put(name, value); } //sort url hash map by key Set c = param.entrySet(); Iterator it = c.iterator(); while (it.hasNext()) { Map.Entry me = (Map.Entry) it.next(); String key = (String) me.getKey(); String value = (String) me.getValue(); try { temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&"; } catch (Exception ex) { s_logger.error("Unable to set parameter " + value + " for the command " + param.get("command"), ex); } } temp = temp.substring(0, temp.length() - 1); String requestToSign = req + temp; String signature = UtilsForTest.signRequest(requestToSign, secretKey); String encodedSignature = ""; try { encodedSignature = URLEncoder.encode(signature, "UTF-8"); } catch (Exception ex) { ex.printStackTrace(); } String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?" + temp + "&Signature=" + encodedSignature; s_logger.info("Sending request with url: " + url + "\n"); sendRequest(url); }
From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java
/** * Merge a xml file with Velocity template. The third parameter is the properties file, where the * key/value is added to the velocity context. The fourth parameter is the output file. If not * included, the result is printed to system.out. * //from www . ja v a 2 s . com * @param args are file.xml template.vm properties.prop [output.file] * @throws JDOMException if the xml file couldn't be parsed * @throws IOException couldn't find one of the files */ public static void main(String[] args) throws JDOMException, IOException { if (args.length < 3) { System.out.println( "Missing input files. XMLToVelocity file.xml template.vm prop.properties [output.file]"); return; } final Properties properties = new Properties(); final File prop = new File(args[2]); if (prop.exists()) properties.load(new FileReader(prop)); else throw new IOException("Couldn't find the property file:" + prop.getAbsolutePath()); final MergeXMLWithVelocity xtv = new MergeXMLWithVelocity(properties); xtv.create(args); }
From source file:net.ontopia.topicmaps.db2tm.CSVImport.java
public static void main(String[] argv) throws Exception { // Initialize logging CmdlineUtils.initializeLogging();//from www. jav a2s. c om // Initialize command line option parser and listeners CmdlineOptions options = new CmdlineOptions("CSVImport", argv); OptionsListener ohandler = new OptionsListener(); // Register local options options.addLong(ohandler, "separator", 's', true); options.addLong(ohandler, "stripquotes", 'q'); options.addLong(ohandler, "ignorelines", 'i', true); // Register logging options CmdlineUtils.registerLoggingOptions(options); // Parse command line options try { options.parse(); } catch (CmdlineOptions.OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Get command line arguments String[] args = options.getArguments(); if (args.length < 2) { System.err.println("Error: wrong number of arguments."); usage(); System.exit(1); } String dbprops = args[0]; String csvfile = args[1]; String table = (args.length >= 3 ? args[2] : null); if (table == null) { if (csvfile.endsWith(".csv")) table = csvfile.substring(0, csvfile.length() - 4); else table = csvfile; } String[] columns = (args.length >= 4 ? StringUtils.split(args[3], ",") : null); // Load property file Properties props = new Properties(); props.load(new FileInputStream(dbprops)); // Create database connection DefaultConnectionFactory cfactory = new DefaultConnectionFactory(props, false); Connection conn = cfactory.requestConnection(); CSVImport ci = new CSVImport(conn); ci.setTable(table); ci.setColumns(columns); ci.setSeparator(ohandler.separator); ci.setClearTable(true); ci.setStripQuotes(ohandler.stripquotes); ci.setIgnoreColumns(true); ci.setIgnoreLines(ohandler.ignorelines); ci.importCSV(new FileInputStream(csvfile)); }
From source file:edu.indiana.d2i.sloan.internal.LaunchVMSimulator.java
/** * @param args/*from w w w . jav a 2 s .c om*/ */ public static void main(String[] args) { LaunchVMSimulator simulator = new LaunchVMSimulator(); CommandLineParser parser = new PosixParser(); try { CommandLine line = simulator.parseCommandLine(parser, args); String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR)); String mode = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE)); String policyFilePath = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.POLICY_PATH)); if (!HypervisorCmdSimulator.resourceExist(wdir)) { logger.error(String.format("Cannot find VM working dir: %s", wdir)); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_EXIST)); } VMMode vmmode = HypervisorCmdSimulator.getVMMode(mode); if (vmmode == null) { logger.error(String.format("Invalid requested mode: %s, can only be %s or %s", mode, VMMode.MAINTENANCE.toString(), VMMode.SECURE.toString())); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_VM_MODE)); } if (!HypervisorCmdSimulator.resourceExist(policyFilePath)) { logger.error(String.format("Cannot find plicy file: %s", policyFilePath)); System.exit(ERROR_CODE.get(ERROR_STATE.FIREWALL_POLICY_NOT_EXIST)); } // load VM status info Properties prop = new Properties(); String filename = HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME; prop.load(new FileInputStream(new File(filename))); // can only launch VM when it is in shutdown state VMState currentState = VMState.valueOf(prop.getProperty(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE))); if (!currentState.equals(VMState.SHUTDOWN)) { logger.error(String.format("Can only launch VM when it is in %s state, current VM state is %s", VMState.SHUTDOWN.toString(), currentState.toString())); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_SHUTDOWN)); } // launch VM try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } // update VM state file // set following properties prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.POLICY_PATH), policyFilePath); prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE), vmmode.toString()); // set VM state to running prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE), VMState.RUNNING.toString()); // save VM state file back prop.store(new FileOutputStream(new File(filename)), ""); // success System.exit(0); } catch (ParseException e) { logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s", StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, ""))); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS)); } catch (FileNotFoundException e) { logger.error(String.format("Cannot find vm state file: %s", e.getMessage())); System.exit(ERROR_CODE.get(ERROR_STATE.VM_STATE_FILE_NOT_FOUND)); } catch (IOException e) { logger.error(e.getMessage(), e); System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR)); } }
From source file:net.ontopia.persistence.rdbms.CSVImport.java
public static void main(String[] argv) throws Exception { // Initialize logging CmdlineUtils.initializeLogging();/*from ww w .j a v a 2 s.c o m*/ // Initialize command line option parser and listeners CmdlineOptions options = new CmdlineOptions("CSVImport", argv); OptionsListener ohandler = new OptionsListener(); // Register local options options.addLong(ohandler, "separator", 's', true); options.addLong(ohandler, "stripquotes", 'q'); options.addLong(ohandler, "ignorelines", 'i', true); // Register logging options CmdlineUtils.registerLoggingOptions(options); // Parse command line options try { options.parse(); } catch (CmdlineOptions.OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Get command line arguments String[] args = options.getArguments(); if (args.length < 4) { System.err.println("Error: wrong number of arguments."); usage(); System.exit(1); } String schema = args[0]; String dbprops = args[1]; String csvfile = args[2]; String table = args[3]; String[] columns = StringUtils.split(args[4], ","); // Load property file Properties props = new Properties(); props.load(new FileInputStream(dbprops)); // Create database connection DefaultConnectionFactory cfactory = new DefaultConnectionFactory(props, false); Connection conn = cfactory.requestConnection(); CSVImport ci = new CSVImport(DatabaseProjectReader.loadProject(schema), conn); ci.setTable(table); ci.setColumns(columns); ci.setSeparator(ohandler.separator); ci.setClearTable(true); ci.setStripQuotes(ohandler.stripquotes); ci.setIgnoreColumns(true); ci.setIgnoreLines(ohandler.ignorelines); ci.importCSV(new FileInputStream(csvfile)); }
From source file:de.mfo.jsurf.Main.java
/** * @param args/*from ww w . java 2 s .c om*/ */ public static void main(String[] args) { String jsurf_filename = ""; Options options = new Options(); options.addOption("s", "size", true, "width (and height) of a image (default: " + size + ")"); options.addOption("q", "quality", true, "quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); options.addOption("o", "output", true, "output PNG into this file (- means standard output. Use ./- to denote a file literally named -.)"); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "jsurf [options] jsurf_file"; String help_header = "jsurf is a renderer for algebraic surfaces. If - is specified as a filename the jsurf file is read from standard input. " + "Use ./- to denote a file literally named -."; String help_footer = ""; try { CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length > 0) jsurf_filename = cmd.getArgs()[0]; else { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption("output")) { } if (cmd.hasOption("size")) size = Integer.parseInt(cmd.getOptionValue("size")); int quality = 1; if (cmd.hasOption("quality")) quality = Integer.parseInt(cmd.getOptionValue("quality")); switch (quality) { case 0: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_1x1; break; case 2: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 3: aam = AntiAliasingMode.SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 1: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.QUINCUNX; } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); System.exit(-1); } catch (NumberFormatException nfe) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); System.exit(-1); } final Properties jsurf = new Properties(); try { if (jsurf_filename.equals("-")) jsurf.load(System.in); else jsurf.load(new FileReader(jsurf_filename)); FileFormat.load(jsurf, asr); } catch (Exception e) { System.err.println("Unable to read jsurf file " + jsurf_filename); e.printStackTrace(); System.exit(-2); } asr.setAntiAliasingMode(aam); asr.setAntiAliasingPattern(aap); // display the image in a window final String window_title = "jsurf: " + jsurf_filename; SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame(window_title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSurferRenderPanel p = null; try { p = new JSurferRenderPanel(jsurf); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } f.setContentPane(p); // f.getContentPane().add( new JLabel( new ImageIcon( window_image ) ) ); f.pack(); // f.setResizable( false ); f.setVisible(true); } }); }
From source file:edu.indiana.d2i.sloan.internal.SwitchVMSimulator.java
/** * @param args/*from ww w . j av a2s . c om*/ */ public static void main(String[] args) { SwitchVMSimulator simulator = new SwitchVMSimulator(); CommandLineParser parser = new PosixParser(); try { CommandLine line = simulator.parseCommandLine(parser, args); String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR)); String mode = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE)); String policyFilePath = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.POLICY_PATH)); if (!HypervisorCmdSimulator.resourceExist(wdir)) { logger.error(String.format("Cannot find VM working dir: %s", wdir)); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_EXIST)); } VMMode requestedMode = HypervisorCmdSimulator.getVMMode(mode); if (requestedMode == null) { logger.error(String.format("Invalid requested mode: %s, can only be %s or %s", mode, VMMode.MAINTENANCE.toString(), VMMode.SECURE.toString())); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_VM_MODE)); } if (!HypervisorCmdSimulator.resourceExist(policyFilePath)) { logger.error(String.format("Cannot find plicy file: %s", policyFilePath)); System.exit(ERROR_CODE.get(ERROR_STATE.FIREWALL_POLICY_NOT_EXIST)); } // load VM state file Properties prop = new Properties(); String filename = HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME; prop.load(new FileInputStream(new File(filename))); // cannot switch when VM is not running VMState currentState = VMState.valueOf(prop.getProperty(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE))); if (!currentState.equals(VMState.RUNNING)) { logger.error("Cannot perform switch when VM is not running"); System.exit(ERROR_CODE.get(ERROR_STATE.VM_NOT_RUNNING)); } // get current mode VMMode currentMode = VMMode.valueOf(prop.getProperty(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE))); if (currentMode.equals(requestedMode)) { logger.error(String.format("VM is already in the requested mode: %s", requestedMode.toString())); System.exit(ERROR_CODE.get(ERROR_STATE.VM_ALREADY_IN_REQUESTED_MODE)); } // switch VM try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error(e.getMessage()); } // update firewall policy prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.POLICY_PATH), policyFilePath); // update VM status file, i.e. set mode to the requested mode prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE), requestedMode.toString()); // save VM state file back prop.store(new FileOutputStream(new File(filename)), ""); // success System.exit(0); } catch (ParseException e) { logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s", StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, ""))); System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS)); } catch (FileNotFoundException e) { logger.error(String.format("Cannot find vm state file: %s", e.getMessage())); System.exit(ERROR_CODE.get(ERROR_STATE.VM_STATE_FILE_NOT_FOUND)); } catch (IOException e) { logger.error(e.getMessage(), e); System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR)); } }
From source file:com.yahoo.pulsar.client.cli.PulsarClientTool.java
public static void main(String[] args) throws Exception { if (args.length == 0) { System.out.println("Usage: pulsar-client CONF_FILE_PATH [options] [command] [command options]"); System.exit(-1);/*w w w . j a v a 2 s . c om*/ } String configFile = args[0]; Properties properties = new Properties(); if (configFile != null) { FileInputStream fis = null; try { fis = new FileInputStream(configFile); properties.load(fis); } finally { if (fis != null) { fis.close(); } } } PulsarClientTool clientTool = new PulsarClientTool(properties); int exit_code = clientTool.run(Arrays.copyOfRange(args, 1, args.length)); System.exit(exit_code); }
From source file:se.vgregion.portal.cs.util.CryptoUtilImpl.java
/** * Main method used for creating initial key file. * /*from w w w.j a v a 2 s . c o m*/ * @param args * - not used */ public static void main(String[] args) { final String keyFile = "./howto.key"; final String pwdFile = "./howto.properties"; CryptoUtilImpl cryptoUtils = new CryptoUtilImpl(); cryptoUtils.setKeyFile(new File(keyFile)); String clearPwd = "my_cleartext_pwd"; Properties p1 = new Properties(); Writer w = null; try { p1.put("user", "liferay"); String encryptedPwd = cryptoUtils.encrypt(clearPwd); p1.put("pwd", encryptedPwd); w = new FileWriter(pwdFile); p1.store(w, ""); } catch (GeneralSecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (w != null) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } } // ================== Properties p2 = new Properties(); Reader r = null; try { r = new FileReader(pwdFile); p2.load(r); String encryptedPwd = p2.getProperty("pwd"); System.out.println(encryptedPwd); System.out.println(cryptoUtils.decrypt(encryptedPwd)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (GeneralSecurityException e) { e.printStackTrace(); } finally { if (r != null) { try { r.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.linkedin.thirdeye.hadoop.aggregation.AggregationPhaseJob.java
public static void main(String[] args) throws Exception { if (args.length != 1) { throw new IllegalArgumentException("usage: config.properties"); }/*w ww. j av a2 s.c o m*/ Properties props = new Properties(); props.load(new FileInputStream(args[0])); AggregationPhaseJob job = new AggregationPhaseJob("aggregate_avro_job", props); job.run(); }