List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:edu.osu.ling.pep.Pep.java
/** * Invokes Pep from the command line.//ww w . j a va2 s. c o m * <p> * The main work this method does, apart from tokenizing the arguments and * input tokens, is to load and parse the XML grammar file (as specified by * <code>-g</code> or <code>--grammar</code>). If any of the arguments * <code>-g</code>, <code>--grammar</code>, <code>-s</code>, * <code>--seed</code>, <code>-o</code>, <code>--option</code>, occur with * no argument following, this method prints an error notifying the user. * * @param args * The expected arguments are as follows, and can occur in any * particular order: * <ul> * <li><code>-g|--grammar <grammar file></code></li> <li> * <code>-s|--seed <seed category></code></li> <li><code> * -v|--verbose {verbosity level}</code></li> <li><code> * -o|--option <OPTION_NAME=value></code></li> <li><code> * -h|--help (prints usage information)</code></li> <li><code> * <token1 ... token<em>n</em>></code> (or <code>-</code> * for standard input)</li> * </ul> * <code>OPTION_NAME</code> must be the name of one of the * recognized {@link ParserOption options}. If <code>-h</code> or * <code>--help</code> occur anywhere in the arguments, usage * information is printed and no parsing takes place. */ @SuppressWarnings("static-access") public static final void main(final String[] args) { try { final Options opts = new Options(); opts.addOption(OptionBuilder.withLongOpt("grammar").withDescription("the grammar to use").hasArg() .isRequired().withArgName("grammar file").create('g')); opts.addOption(OptionBuilder.withLongOpt("seed").withDescription("the seed category to parse for") .hasArg().isRequired().withArgName("seed category").create('s')); opts.addOption(OptionBuilder.withLongOpt("verbose").withDescription("0-3").hasOptionalArg() .withArgName("verbosity level").create('v')); opts.addOption(OptionBuilder.withLongOpt("option").withDescription("sets parser options") .withArgName("OPTION=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("o")); opts.addOption(OptionBuilder.withLongOpt("help").withDescription("prints this message").create('h')); final CommandLineParser parser = new GnuParser(); try { final CommandLine line = parser.parse(opts, args); if (line.hasOption('h')) { Pep.printHelp(opts); } else { final int v = Integer.parseInt(line.getOptionValue('v', Integer.toString(Pep.V_PARSE))); if (v < 0) { throw new PepException("verbosity < 0: " + v); } Pep.verbosity = v; final Map<ParserOption, Boolean> options = new EnumMap<ParserOption, Boolean>( ParserOption.class); final Properties props = line.getOptionProperties("o"); for (final Object key : props.keySet()) { try { options.put(ParserOption.valueOf(key.toString()), Boolean.valueOf(props.get(key).toString())); } catch (final IllegalArgumentException iae) { Pep.printError("no option named " + key.toString()); Pep.printHelp(opts); return; } } final Pep pep = new Pep(options); // final Grammar grammar = // new GrammarParser(Pep.findGrammar(line // .getOptionValue('g'))).t.parse(); final List<?> ts = line.getArgList(); List<String> tokens = null; if (ts.isEmpty() || ts.get(0).equals("-")) { tokens = Pep.readTokens(new Scanner(System.in)); } else { tokens = new ArrayList<String>(ts.size()); for (final Object t : ts) { tokens.add(t.toString()); } } pep.lastParseStart = System.currentTimeMillis(); // try { // pep.parse(grammar, tokens, // new Category(line.getOptionValue('s'))); // } catch (final PepException ignore) { // // ignore here, we're listening // } } } catch (final ParseException pe) { Pep.printError("command-line syntax problem: " + pe.getMessage()); Pep.printHelp(opts); } } catch (final PepException pe) { final Throwable cause = pe.getCause(); Pep.printError((cause == null) ? pe : cause); } catch (final RuntimeException re) { Pep.printError(re); } }
From source file:com.googlecode.dex2jar.bin_gen.BinGen.java
/** * @param args/*from w ww . ja v a2 s. co m*/ * @throws IOException */ public static void main(String[] args) throws IOException { Properties p = new Properties(); p.load(BinGen.class.getResourceAsStream("class.cfg")); String bat = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/bat_template"), "UTF-8"); String sh = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/sh_template"), "UTF-8"); File binDir = new File("src/main/bin"); String setclasspath = FileUtils.readFileToString( new File("src/main/resources/com/googlecode/dex2jar/bin_gen/setclasspath.bat"), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, "setclasspath.bat"), setclasspath, "UTF-8"); for (Object key : p.keySet()) { String name = key.toString(); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".sh"), sh.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); FileUtils.writeStringToFile(new File(binDir, key.toString() + ".bat"), bat.replaceAll("__@class_name@__", p.getProperty(name)), "UTF-8"); } }
From source file:edu.hku.sdb.driver.SdbDriver.java
/** * @param args//from ww w . ja v a 2 s.c o m */ public static void main(String[] args) { CommandLine line = parseAndValidateInput(args); String confDir = line.getOptionValue(CONF); Properties properties = line.getOptionProperties("D"); File sdbConnectionConfigFile = new File(confDir + "/" + ConnectionConf.CONF_FILE); File sdbServerConfigFile = new File(confDir + "/" + ServerConf.CONF_FILE); File sdbMetadbConfigFile = new File(confDir + "/" + MetadbConf.CONF_FILE); XMLPropParser propParser = new XMLPropParser(); // Parse all the sdb connection config Map<String, String> prop = propParser.importXML(sdbConnectionConfigFile); // Parse all the server config prop.putAll(propParser.importXML(sdbServerConfigFile)); // Parse all the metadb config prop.putAll(propParser.importXML(sdbMetadbConfigFile)); // Override the config if any Set<Object> states = properties.keySet(); // get set-view of keys for (Object object : states) { String key = (String) object; String value = properties.getProperty(key); prop.put(key, value); } // Cet log4j config PropertyConfigurator.configure(confDir + "/" + "log4j.properties"); ServerConf serverConf = ServerConfFactory.getServerConf(prop); MetadbConf metadbConf = MetadbConfFactory.getMetadbConf(prop); ConnectionConf connectionConf = new ConnectionConf(prop); SdbConf sdbConf = new SdbConf(connectionConf, serverConf, metadbConf); // Start the SDB proxy startConnectionPool(sdbConf); }
From source file:eu.planets_project.tb.gui.backing.exp.ExpTypeMigrate.java
public static void main(String args[]) { Properties p = System.getProperties(); ByteArrayOutputStream byos = new ByteArrayOutputStream(); try {/*from ww w . j av a 2 s .co m*/ p.storeToXML(byos, "Automatically generated for PLANETS Service ", "UTF-8"); String res = byos.toString("UTF-8"); System.out.println(res); } catch (IOException e) { e.printStackTrace(); } // This. List<String> pl = new ArrayList<String>(); for (Object key : p.keySet()) { pl.add((String) key); } Collections.sort(pl); // for (String key : pl) { System.out.println(key + " = " + p.getProperty(key)); } /* * http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/ThreadMXBean.html#getCurrentThreadCpuTime() * * http://www.java-forums.org/new-java/5303-how-determine-cpu-usage-using-java.html * */ ThreadMXBean TMB = ManagementFactory.getThreadMXBean(); int mscale = 1000000; long time = 0, time2 = 0; long cput = 0, cput2 = 0; double cpuperc = -1; //Begin loop. for (int i = 0; i < 10; i++) { if (TMB.isThreadCpuTimeSupported()) { if (!TMB.isThreadCpuTimeEnabled()) { TMB.setThreadCpuTimeEnabled(true); } // if(new Date().getTime() * mscale - time > 1000000000) //Reset once per second // { System.out.println("Resetting..."); time = System.currentTimeMillis() * mscale; cput = TMB.getCurrentThreadCpuTime(); // cput = TMB.getCurrentThreadUserTime(); // } } //Do cpu intensive stuff for (int k = 0; k < 10; k++) { for (int j = 0; j < 100000; j++) { double a = Math.pow(i, j); double b = a / j + Math.random(); a = b * Math.random(); b = a * Math.random(); } try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } if (TMB.isThreadCpuTimeSupported()) { // if(new Date().getTime() * mscale - time != 0) { cput2 = TMB.getCurrentThreadCpuTime(); System.out.println("cpu: " + (cput2 - cput) / (1000.0 * mscale)); // cput2 = TMB.getCurrentThreadUserTime(); time2 = System.currentTimeMillis() * mscale; System.out.println("time: " + (time2 - time) / (1000.0 * mscale)); cpuperc = 100.0 * (cput2 - cput) / (double) (time2 - time); System.out.println("cpu perc = " + cpuperc); // } } //End Loop } System.out.println("Done."); }
From source file:com.mgreau.jboss.as7.cli.CliLauncher.java
public static void main(String[] args) throws Exception { int exitCode = 0; CommandContext cmdCtx = null;/*from w ww .j a v a2s . c o m*/ boolean gui = false; String appName = ""; try { String argError = null; List<String> commands = null; File file = null; boolean connect = false; String defaultControllerProtocol = "http-remoting"; String defaultControllerHost = null; int defaultControllerPort = -1; boolean version = false; String username = null; char[] password = null; int connectionTimeout = -1; //App deployment boolean isAppDeployment = false; final Properties props = new Properties(); for (String arg : args) { if (arg.startsWith("--controller=") || arg.startsWith("controller=")) { final String fullValue; final String value; if (arg.startsWith("--")) { fullValue = arg.substring(13); } else { fullValue = arg.substring(11); } final int protocolEnd = fullValue.lastIndexOf("://"); if (protocolEnd == -1) { value = fullValue; } else { value = fullValue.substring(protocolEnd + 3); defaultControllerProtocol = fullValue.substring(0, protocolEnd); } String portStr = null; int colonIndex = value.lastIndexOf(':'); if (colonIndex < 0) { // default port defaultControllerHost = value; } else if (colonIndex == 0) { // default host portStr = value.substring(1); } else { final boolean hasPort; int closeBracket = value.lastIndexOf(']'); if (closeBracket != -1) { //possible ip v6 if (closeBracket > colonIndex) { hasPort = false; } else { hasPort = true; } } else { //probably ip v4 hasPort = true; } if (hasPort) { defaultControllerHost = value.substring(0, colonIndex).trim(); portStr = value.substring(colonIndex + 1).trim(); } else { defaultControllerHost = value; } } if (portStr != null) { int port = -1; try { port = Integer.parseInt(portStr); if (port < 0) { argError = "The port must be a valid non-negative integer: '" + args + "'"; } else { defaultControllerPort = port; } } catch (NumberFormatException e) { argError = "The port must be a valid non-negative integer: '" + arg + "'"; } } } else if ("--connect".equals(arg) || "-c".equals(arg)) { connect = true; } else if ("--version".equals(arg)) { version = true; } else if ("--gui".equals(arg)) { gui = true; } else if (arg.startsWith("--appDeployment=") || arg.startsWith("appDeployment=")) { isAppDeployment = true; appName = arg.startsWith("--") ? arg.substring(16) : arg.substring(14); } else if (arg.startsWith("--file=") || arg.startsWith("file=")) { if (file != null) { argError = "Duplicate argument '--file'."; break; } if (commands != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } final String fileName = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); if (!fileName.isEmpty()) { file = new File(fileName); if (!file.exists()) { argError = "File " + file.getAbsolutePath() + " doesn't exist."; break; } } else { argError = "Argument '--file' is missing value."; break; } } else if (arg.startsWith("--commands=") || arg.startsWith("commands=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(11) : arg.substring(9); commands = Util.splitCommands(value); } else if (arg.startsWith("--command=") || arg.startsWith("command=")) { if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time."; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } final String value = arg.startsWith("--") ? arg.substring(10) : arg.substring(8); commands = Collections.singletonList(value); } else if (arg.startsWith("--user=")) { username = arg.startsWith("--") ? arg.substring(7) : arg.substring(5); } else if (arg.startsWith("--password=")) { password = (arg.startsWith("--") ? arg.substring(11) : arg.substring(9)).toCharArray(); } else if (arg.startsWith("--timeout=")) { if (connectionTimeout > 0) { argError = "Duplicate argument '--timeout'"; break; } final String value = arg.substring(10); try { connectionTimeout = Integer.parseInt(value); } catch (final NumberFormatException e) { // } if (connectionTimeout <= 0) { argError = "The timeout must be a valid positive integer: '" + value + "'"; } } else if (arg.equals("--help") || arg.equals("-h")) { commands = Collections.singletonList("help"); } else if (arg.startsWith("--properties=")) { final String value = arg.substring(13); final File propertiesFile = new File(value); if (!propertiesFile.exists()) { argError = "File doesn't exist: " + propertiesFile.getAbsolutePath(); break; } FileInputStream fis = null; try { fis = new FileInputStream(propertiesFile); props.load(fis); } catch (FileNotFoundException e) { argError = e.getLocalizedMessage(); break; } catch (java.io.IOException e) { argError = "Failed to load properties from " + propertiesFile.getAbsolutePath() + ": " + e.getLocalizedMessage(); break; } finally { if (fis != null) { try { fis.close(); } catch (java.io.IOException e) { } } } for (final Object prop : props.keySet()) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { System.setProperty((String) prop, (String) props.get(prop)); return null; } }); } } else if (!(arg.startsWith("-D") || arg.equals("-XX:"))) {// skip system properties and jvm options // assume it's commands if (file != null) { argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time: " + arg; break; } if (commands != null) { argError = "Duplicate argument '--command'/'--commands'."; break; } commands = Util.splitCommands(arg); } } if (argError != null) { System.err.println(argError); exitCode = 1; return; } if (version) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); VersionHandler.INSTANCE.handle(cmdCtx); return; } if (file != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processFile(file, cmdCtx, isAppDeployment, appName, props); return; } if (commands != null) { cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, false, connect, connectionTimeout); processCommands(commands, cmdCtx); return; } // Interactive mode cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort, username, password, true, connect, connectionTimeout); cmdCtx.interact(); } catch (Throwable t) { t.printStackTrace(); exitCode = 1; } finally { if (cmdCtx != null && cmdCtx.getExitCode() != 0) { exitCode = cmdCtx.getExitCode(); } if (!gui) { System.exit(exitCode); } } System.exit(exitCode); }
From source file:Main.java
public static void clearProperties(Properties props, Collection<String> names) { props.keySet().removeAll(names); }
From source file:com.vamonossoftware.core.TextUtil.java
/** * Replaces variables in a string with values from a properties object. * So, if the string is//from ww w .jav a 2 s . com * "Hello ${name}." * And the properties contains * "name" -> "Mr Ed" * Then the result will be * "Hello Mr Ed." */ public static String replace(String input, Properties properties) { for (Object key : properties.keySet()) { input = StringUtils.replace(input, START + key + END, properties.getProperty((String) key)); } return input; }
From source file:org.openvpms.component.business.service.security.memory.UserMapEditor.java
public static UserMap addUsersFromProperties(UserMap userMap, Properties props) { for (Object o : props.keySet()) { String username = (String) o; String value = props.getProperty(username); // now retrieve the rest of the user details including the // details and the authorities String[] tokens = StringUtils.commaDelimitedListToStringArray(value); String password = tokens[0]; // the rest need to be granted authorities ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (int index = 1; index < tokens.length; index++) { authorities.add(new ArchetypeAwareGrantedAuthority(tokens[index])); }/* w w w. j a v a 2 s . c o m*/ userMap.addUser(new User(username, password, true)); } return userMap; }
From source file:Main.java
/** * Return serializable data, the format of these data is placed like the following format * ${key}=${value}/*w ww . ja v a 2 s .com*/ * * @param properties Properties instance * @return serializable data * @throws java.io.UnsupportedEncodingException * if errors occure during text converted to UTF-8 encoding */ public static byte[] getSerializablePropertiesData(Properties properties) throws UnsupportedEncodingException { Set keySet = properties.keySet(); TreeSet keys = new TreeSet(keySet); Iterator it = keys.iterator(); StringBuffer bf = new StringBuffer(); while (it.hasNext()) { String item = (String) it.next(); String resourceValue = (String) properties.get(item); bf.append(item); bf.append("="); bf.append(resourceValue); bf.append("\n"); } return bf.toString().getBytes("UTF-8"); }
From source file:Main.java
public static Map<String, String> propertiesToMap(Properties properties) { final Map<String, String> result = new HashMap<String, String>(); for (final Object propKey : properties.keySet()) { result.put(propKey.toString(), properties.getProperty(propKey.toString())); }/*from www. j a va 2s. c o m*/ return result; }