List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:Main.java
public static void main(String[] args) throws IOException { Properties properties = new Properties(); try (InputStream input = new FileInputStream("test.properties")) { properties.load(input);//from w ww .j a v a 2 s. c o m } for (String key : properties.stringPropertyNames()) { System.out.println(key + " = '" + properties.get(key) + "'"); } }
From source file:Main.java
public static void main(String[] args) { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); prop.put("tutorial", "java2s.com"); // save the Property names in the set Set<String> set = prop.stringPropertyNames(); System.out.println(set);/*w w w .j a va 2 s. c o m*/ }
From source file:com.github.jcustenborder.kafka.connect.spooldir.SchemaGenerator.java
public static void main(String... args) throws Exception { ArgumentParser parser = ArgumentParsers.newArgumentParser("CsvSchemaGenerator").defaultHelp(true) .description("Generate a schema based on a file."); parser.addArgument("-t", "--type").required(true).choices("csv", "json") .help("The type of generator to use."); parser.addArgument("-c", "--config").type(File.class); parser.addArgument("-f", "--file").type(File.class).required(true) .help("The data file to generate the schema from."); parser.addArgument("-i", "--id").nargs("*").help("Field(s) to use as an identifier."); parser.addArgument("-o", "--output").type(File.class) .help("Output location to write the configuration to. Stdout is default."); Namespace ns = null;/* www . j a va 2 s . c o m*/ try { ns = parser.parseArgs(args); } catch (ArgumentParserException ex) { parser.handleError(ex); System.exit(1); } File inputFile = ns.get("file"); List<String> ids = ns.getList("id"); if (null == ids) { ids = ImmutableList.of(); } Map<String, Object> settings = new LinkedHashMap<>(); File inputPropertiesFile = ns.get("config"); if (null != inputPropertiesFile) { Properties inputProperties = new Properties(); try (FileInputStream inputStream = new FileInputStream(inputPropertiesFile)) { inputProperties.load(inputStream); } for (String s : inputProperties.stringPropertyNames()) { Object v = inputProperties.getProperty(s); settings.put(s, v); } } final SchemaGenerator generator; final String type = ns.getString("type"); if ("csv".equalsIgnoreCase(type)) { generator = new CsvSchemaGenerator(settings); } else if ("json".equalsIgnoreCase(type)) { generator = new JsonSchemaGenerator(settings); } else { throw new UnsupportedOperationException( String.format("'%s' is not a supported schema generator type", type)); } Map.Entry<Schema, Schema> kvp = generator.generate(inputFile, ids); Properties properties = new Properties(); properties.putAll(settings); properties.setProperty(SpoolDirSourceConnectorConfig.KEY_SCHEMA_CONF, ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getKey())); properties.setProperty(SpoolDirSourceConnectorConfig.VALUE_SCHEMA_CONF, ObjectMapperFactory.INSTANCE.writeValueAsString(kvp.getValue())); String output = ns.getString("output"); final String comment = "Configuration was dynamically generated. Please verify before submitting."; if (Strings.isNullOrEmpty(output)) { properties.store(System.out, comment); } else { try (FileOutputStream outputStream = new FileOutputStream(output)) { properties.store(outputStream, comment); } } }
From source file:uk.ac.gate.cloud.cli.Main.java
/** * @param args/*from ww w . j a v a2 s . c o m*/ */ public static void main(String... args) throws Exception { Properties commands = new Properties(); InputStream commandsStream = Main.class.getResourceAsStream("commands.properties"); commands.load(commandsStream); commandsStream.close(); if (args.length < 1) { System.err.println("No command name provided, valid commands are:"); List<String> validCommands = new ArrayList<String>(); validCommands.add("configure"); validCommands.addAll(commands.stringPropertyNames()); Collections.sort(validCommands); for (String cmd : validCommands) { System.err.println(" " + cmd); } System.exit(1); } if ("configure".equals(args[0])) { doConfigure(); } RestClient client = createClient(); String command = args[0]; String commandClass = commands.getProperty(command); if (commandClass == null) { System.err.println("Unknown command \"" + command + "\""); System.exit(1); } Command cmd = Class.forName(commands.getProperty(command)).asSubclass(Command.class).newInstance(); String[] cmdArgs = new String[args.length - 1]; System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length); try { cmd.run(client, cmdArgs); } catch (RestClientException e) { String response = (e.getResponse() == null) ? "(no detail available)" : e.getResponse().at("/message").asText(); System.err.println(e.getMessage() + ": " + response); } }
From source file:org.apache.hadoop.hive.llap.LlapDump.java
public static void main(String[] args) throws Exception { Options opts = createOptions();// www . ja va 2 s . c om CommandLine cli = new GnuParser().parse(opts, args); if (cli.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("llapdump", opts); return; } if (cli.hasOption('l')) { url = cli.getOptionValue("l"); } if (cli.hasOption('u')) { user = cli.getOptionValue("u"); } if (cli.hasOption('p')) { pwd = cli.getOptionValue("p"); } if (cli.hasOption('n')) { numSplits = cli.getOptionValue("n"); } Properties configProps = cli.getOptionProperties("hiveconf"); if (cli.getArgs().length > 0) { query = cli.getArgs()[0]; } if (query == null) { throw new IllegalArgumentException("No query string specified"); } System.out.println("url: " + url); System.out.println("user: " + user); System.out.println("query: " + query); LlapRowInputFormat format = new LlapRowInputFormat(); JobConf job = new JobConf(); job.set(LlapBaseInputFormat.URL_KEY, url); job.set(LlapBaseInputFormat.USER_KEY, user); job.set(LlapBaseInputFormat.PWD_KEY, pwd); job.set(LlapBaseInputFormat.QUERY_KEY, query); // Additional conf settings specified on the command line for (String key : configProps.stringPropertyNames()) { job.set(key, configProps.getProperty(key)); } InputSplit[] splits = format.getSplits(job, Integer.parseInt(numSplits)); if (splits.length == 0) { System.out.println("No splits returned - empty scan"); System.out.println("Results: "); } else { boolean first = true; for (InputSplit s : splits) { LOG.info("Processing input split s from " + Arrays.toString(s.getLocations())); RecordReader<NullWritable, Row> reader = format.getRecordReader(s, job, null); if (reader instanceof LlapRowRecordReader && first) { Schema schema = ((LlapRowRecordReader) reader).getSchema(); System.out.println("" + schema); } if (first) { System.out.println("Results: "); System.out.println(""); first = false; } Row value = reader.createValue(); while (reader.next(NullWritable.get(), value)) { printRow(value); } } System.exit(0); } }
From source file:org.objectrepository.MessageConsumerDaemon.java
/** * main/* w w w .ja v a 2 s .c o m*/ * <p/> * Accepts one folder as argument: -messageQueues * That folder ought to contain one or more folders ( or symbolic links ) to the files * The folder has the format: [foldername] or [foldername].[maxTasks] * MaxTasks is to indicate the total number of jobs being able to run. * * long * * @param argv */ public static void main(String[] argv) { if (instance == null) { final Properties properties = new Properties(); if (argv.length > 0) { for (int i = 0; i < argv.length; i += 2) { try { properties.put(argv[i], argv[i + 1]); } catch (ArrayIndexOutOfBoundsException arr) { System.out.println("Missing value after parameter " + argv[i]); System.exit(-1); } } } else { log.fatal("Usage: pmq-agent.jar -messageQueues [queues] -heartbeatInterval [interval in ms]\n" + "The queues is a folder that contains symbolic links to the startup scripts."); System.exit(-1); } if (log.isInfoEnabled()) { log.info("Arguments set: "); for (String key : properties.stringPropertyNames()) { log.info("'" + key + "'='" + properties.getProperty(key) + "'"); } } if (!properties.containsKey("-messageQueues")) { log.fatal("Expected case sensitive parameter: -messageQueues"); System.exit(-1); } final File messageQueues = new File((String) properties.get("-messageQueues")); if (!messageQueues.exists()) { log.fatal("Cannot find folder for messageQueues: " + messageQueues.getAbsolutePath()); System.exit(-1); } if (messageQueues.isFile()) { log.fatal( "-messageQueues should point to a folder, not a file: " + messageQueues.getAbsolutePath()); System.exit(-1); } long heartbeatInterval = 600000; if (properties.containsKey("-heartbeatInterval")) { heartbeatInterval = Long.parseLong((String) properties.get("heartbeatInterval")); } String identifier = null; if (properties.containsKey("-id")) { identifier = (String) properties.get("-id"); } else if (properties.containsKey("-identifier")) { identifier = (String) properties.get("-identifier"); } final File[] files = messageQueues.listFiles(); final String[] scriptNames = (properties.containsKey("-startup")) ? new String[] { properties.getProperty("-startup") } : new String[] { "/startup.sh", "\\startup.bat" }; final List<Queue> queues = new ArrayList<Queue>(); for (File file : files) { final String name = file.getName(); final String[] split = name.split("\\.", 2); final String queueName = split[0]; for (String scriptName : scriptNames) { final String shellScript = file.getAbsolutePath() + scriptName; final int maxTask = (split.length == 1) ? 1 : Integer.parseInt(split[1]); log.info("Candidate mq client for " + queueName + " maxTasks " + maxTask); if (new File(shellScript).exists()) { final Queue queue = new Queue(queueName, shellScript, false); queue.setCorePoolSize(1); queue.setMaxPoolSize(maxTask); queue.setQueueCapacity(1); queues.add(queue); break; } else { log.warn("... skipping, because no startup script found at " + shellScript); } } } if (queues.size() == 0) { log.fatal("No queue folders seen in " + messageQueues.getAbsolutePath()); System.exit(-1); } // Add the system queue queues.add(new Queue("Connection", null, true)); getInstance(queues, identifier, heartbeatInterval).run(); } System.exit(0); }
From source file:pt.minha.calibration.Calibrator.java
public static void main(String[] args) throws Throwable { if (args.length != 1) { logger.error("missing command line argument (--server | <servername>)"); } else if (args[0].equals("--server")) { runServer();/*w w w. j a v a 2s . co m*/ } else { Calibrator calib = new Calibrator(args[0]); Properties props = new Properties(); SimpleRegression cpuoh = new SimpleRegression(true); for (int i : new int[] { 100, 1000, 10000, 20000 }) { Map<String, Object> p = new HashMap<String, Object>(); p.put("bench", CPUBenchmark.class.getName()); p.put("samples", 50000); p.put("payload", i); Result r = calib.runReal(p); Result s = calib.runSimulated(p, props); cpuoh.addData(s.meanCPU, r.meanCPU); } props.setProperty("cpuScaling", new Linear(cpuoh.getIntercept(), cpuoh.getSlope()).toString()); // Run double max = Double.MIN_VALUE; SimpleRegression netCPU = new SimpleRegression(true); SimpleRegression netCPU_s = new SimpleRegression(true); for (int i : new int[] { 1, 100, 1000, 4000, 8000, 16000 }) { Map<String, Object> p = new HashMap<String, Object>(); p.put("bench", TCPOverheadBenchmark.class.getName()); p.put("server", new InetSocketAddress(args[0], 20000)); p.put("samples", 5000); p.put("payload", i); Result r = calib.runReal(p); netCPU.addData(i, r.meanCPU); Result s = calib.runSimulated(p, props); netCPU_s.addData(i, s.meanCPU); double bw = 8 * i * 1e9d / r.meanLatency; if (bw > max) max = bw; } props.setProperty("networkBandwidth", Long.toString((long) max)); props.setProperty("tcpOverhead", new Linear((netCPU.getIntercept() - netCPU_s.getIntercept()) / 2, (netCPU.getSlope() - netCPU_s.getSlope()) / 2).toString()); SimpleRegression udpCPU = new SimpleRegression(true); SimpleRegression udpCPU_s = new SimpleRegression(true); for (int i : new int[] { 1, 100, 1000, 4000, 8000, 16000 }) { Map<String, Object> p = new HashMap<String, Object>(); p.put("bench", UDPOverheadBenchmark.class.getName()); p.put("server", new InetSocketAddress(args[0], 20000)); p.put("samples", 5000); p.put("payload", i); Result r = calib.runReal(p); udpCPU.addData(i, r.meanCPU); Result s = calib.runSimulated(p, props); udpCPU_s.addData(i, s.meanCPU); } props.setProperty("udpOverhead", new Linear((udpCPU.getIntercept() - udpCPU_s.getIntercept()) / 2, (udpCPU.getSlope() - udpCPU_s.getSlope()) / 2).toString()); SimpleRegression rtt = new SimpleRegression(true); SimpleRegression rtt_s = new SimpleRegression(true); for (int i : new int[] { 1, 100, 1000, 4000, 8000, 16000 }) { Map<String, Object> p = new HashMap<String, Object>(); p.put("bench", TCPLatencyBenchmark.class.getName()); p.put("server", new InetSocketAddress(args[0], 20000)); p.put("samples", 5000); p.put("payload", i); Result r = calib.runReal(p); rtt.addData(i, r.meanLatency); Result s = calib.runSimulated(p, props); rtt_s.addData(i, s.meanLatency); } props.setProperty("networkLatency", new Linear((rtt.getIntercept() - rtt_s.getIntercept()) / 2, (rtt.getSlope() - rtt_s.getSlope()) / 2).toString()); calib.close(); for (String key : props.stringPropertyNames()) logger.info("result: {}={}", key, props.getProperty(key)); // Write results FileOutputStream file = new FileOutputStream("calibration.properties"); props.store(file, "Generated calibration properties"); file.close(); } }
From source file:Main.java
/** * Returns new properties with <code>String.trim()</code> applied to every property value. The original properties are unchanged. *///from ww w. ja v a 2 s . c o m public static Properties toTrimmedProperties(Properties props) { Properties trimmed = new Properties(); for (String name : props.stringPropertyNames()) { String val = props.getProperty(name); val = val == null ? val : val.trim(); trimmed.setProperty(name, val); } return trimmed; }
From source file:com.cognifide.qa.bb.utils.PropertyUtils.java
private static void overrideFromSystemProperties(Properties properties) { properties.stringPropertyNames().stream().forEach((key) -> { String systemProperty = System.getProperty(key); if (StringUtils.isNotBlank(systemProperty)) { properties.setProperty(key, systemProperty); }/* w ww .ja va 2 s . c o m*/ }); }
From source file:com.textocat.textokit.eval.EvaluationLauncher.java
private static Map<String, String> getPrefixedKeyPairs(Properties props, String prefix) { Map<String, String> result = Maps.newHashMap(); for (String key : props.stringPropertyNames()) { if (key.startsWith(prefix)) { result.put(key.substring(prefix.length()), props.getProperty(key)); }/*from w w w . j a va 2s . co m*/ } return result; }