List of usage examples for java.util Map put
V put(K key, V value);
From source file:iarnrodProducer.java
public static void main(String[] args) throws Exception { // read command line args for a connection to Kafka CommandLineParser parser = new BasicParser(); Options options = getCommonRequiredOptions(); CommandLine cmd = parser.parse(options, args); // create the producer and consumer KafkaDataStore objects Map<String, String> dsConf = getKafkaDataStoreConf(cmd); dsConf.put("isProducer", "true"); DataStore producerDS = DataStoreFinder.getDataStore(dsConf); // verify that we got back our KafkaDataStore objects properly if (producerDS == null) { throw new Exception("Null producer KafkaDataStore"); }// w w w. j a v a 2 s . c om // create the schema which creates a topic in Kafka // (only needs to be done once) final String sftName = "iarnrod"; final String sftSchema = "trainStatus:String,trainCode:String,publicMessage:String,direction:String,dtg:Date,*geom:Point:srid=4326"; SimpleFeatureType sft = SimpleFeatureTypes.createType(sftName, sftSchema); // set zkPath to default if not specified String zkPath = (dsConf.get(ZK_PATH) == null) ? "/geomesa/ds/kafka" : dsConf.get(ZK_PATH); SimpleFeatureType preppedOutputSft = KafkaDataStoreHelper.createStreamingSFT(sft, zkPath); // only create the schema if it hasn't been created already if (!Arrays.asList(producerDS.getTypeNames()).contains(sftName)) producerDS.createSchema(preppedOutputSft); // the live consumer must be created before the producer writes features // in order to read streaming data. // i.e. the live consumer will only read data written after its instantiation SimpleFeatureStore producerFS = (SimpleFeatureStore) producerDS.getFeatureSource(sftName); // creates and adds SimpleFeatures to the producer on an interval System.out.println("Writing features to Kafka... refresh GeoServer layer preview to see changes"); addSimpleFeatures(sft, producerFS); System.exit(0); }
From source file:com.handany.base.generator.Generator.java
public static void main(String[] args) throws IOException { String directoryPath = "src/main/java"; String modelDirectory = directoryPath + File.separator + StringUtils.replace(MODEL_PACKAGE, ".", File.separator) + File.separator; String daoDirectory = directoryPath + File.separator + StringUtils.replace(DAO_PACKAGE, ".", File.separator) + File.separator;// w ww.j av a2 s .co m String serviceDirectory = directoryPath + File.separator + StringUtils.replace(SERVICE_PACKAGE, ".", File.separator) + File.separator; String serviceImplDirectory = directoryPath + File.separator + StringUtils.replace(SERVICE_IMPL_PACKAGE, ".", File.separator) + File.separator; String controllerDirectory = directoryPath + File.separator + StringUtils.replace(CONTROLLER_PACKAGE, ".", File.separator) + File.separator; File fileDirectory = new File(directoryPath); if (!fileDirectory.isDirectory()) { FileUtils.forceMkdir(fileDirectory); } List<TableBean> tableBeanList = getTables(); ArrayList<String> nameList = new ArrayList<>(); // nameList.add("bm_classroom_course"); nameList.add("bm_sales_promotion"); for (TableBean tableBean : tableBeanList) { System.out.println("table:" + tableBean.getTableName()); String tableName = tableBean.getTableName(); if (!nameList.contains(tableName.toLowerCase())) { continue; } Map<String, Object> varMap = new HashMap<>(); varMap.put("tableBean", tableBean); varMap.put("schemaName", SCHEMA_NAME); varMap.put("modelPackage", MODEL_PACKAGE); varMap.put("daoPackage", DAO_PACKAGE); varMap.put("servicePackage", SERVICE_PACKAGE); varMap.put("serviceImplPackage", SERVICE_IMPL_PACKAGE); varMap.put("controllerPackage", CONTROLLER_PACKAGE); Template modelTemplate = FreemarkerUtil.getTemplate("model.ftl"); FreemarkerUtil.outputProcessResult(modelDirectory + tableBean.getTableNameCapitalized() + ".java", modelTemplate, varMap); // Template daoTemplate = FreemarkerUtil.getTemplate("dao.ftl"); // FreemarkerUtil.outputProcessResult(daoDirectory + tableBean.getTableNameCapitalized() + "Mapper.java", daoTemplate, varMap); Template mapperTemplate = FreemarkerUtil.getTemplate("mapper.ftl"); FreemarkerUtil.outputProcessResult(daoDirectory + tableBean.getTableNameCapitalized() + "Mapper.xml", mapperTemplate, varMap); // Template serviceTemplate = FreemarkerUtil.getTemplate("service.ftl"); // FreemarkerUtil.outputProcessResult(serviceDirectory + tableBean.getTableNameCapitalized() + "Service.java", serviceTemplate, varMap); // // Template serviceImplTemplate = FreemarkerUtil.getTemplate("serviceimpl.ftl"); // FreemarkerUtil.outputProcessResult(serviceImplDirectory + tableBean.getTableNameCapitalized() + "ServiceImpl.java", serviceImplTemplate, varMap); // // Template controllerTemplate = FreemarkerUtil.getTemplate("controller.ftl"); // FreemarkerUtil.outputProcessResult(controllerDirectory + tableBean.getTableNameCapitalized() + "Controller.java", controllerTemplate, varMap); } }
From source file:BeanUtilsExampleV3.java
public static void main(String args[]) throws Exception { BeanUtilsExampleV3 diff = new BeanUtilsExampleV3(); Actor actor = diff.prepareData();/* w w w.j a v a 2 s . c o m*/ Map describedData = BeanUtils.describe(actor); // check the map System.err.println(describedData.get("name")); // change this value describedData.put("name", "Robert Redford"); // create a new Actor Bean Actor newActor = new Actor(); BeanUtils.populate(newActor, describedData); System.err.println(BeanUtils.getProperty(newActor, "name")); }
From source file:com.zq.exec.stream.JavaKafkaWordCount.java
public static void main(String[] args) { if (args.length < 4) { System.err.println("Usage: JavaKafkaWordCount <zkQuorum> <group> <topics> <numThreads>"); System.exit(1);/* ww w.j a v a 2s .com*/ } SparkConf sparkConf = new SparkConf().setAppName("JavaKafkaWordCount"); // Create the context with 2 seconds batch size JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, new Duration(2000)); int numThreads = Integer.parseInt(args[3]); Map<String, Integer> topicMap = new HashMap<String, Integer>(); String[] topics = args[2].split(","); for (String topic : topics) { topicMap.put(topic, numThreads); } JavaPairReceiverInputDStream<String, String> messages = KafkaUtils.createStream(jssc, args[0], args[1], topicMap); JavaDStream<String> lines = messages.map(new Function<Tuple2<String, String>, String>() { @Override public String call(Tuple2<String, String> tuple2) { return tuple2._2(); } }); JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterable<String> call(String x) { return Lists.newArrayList(SPACE.split(x)); } }); JavaPairDStream<String, Integer> wordCounts = words.mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { return new Tuple2<String, Integer>(s, 1); } }).reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); wordCounts.map(new Function<Tuple2<String, Integer>, String>() { @Override public String call(Tuple2<String, Integer> v1) throws Exception { System.out.println("---" + v1._1 + "-count---" + v1._2); LOG.info("---" + v1._1 + "-count---" + v1._2); return v1._1 + "=count=" + v1._2; } }).count().print(); // wordCounts.print(); jssc.start(); jssc.awaitTermination(); }
From source file:com.google.appengine.tools.pipeline.impl.util.JsonUtils.java
public static void main(String[] args) throws Exception { JSONObject x = new JSONObject(); x.put("first", 5); x.put("second", 7); debugPrint("hello"); debugPrint(7);/*from www. ja v a2s.c o m*/ debugPrint(3.14159); debugPrint(""); debugPrint('x'); debugPrint(x); debugPrint(null); Map<String, Integer> map = new HashMap<>(); map.put("first", 5); map.put("second", 7); debugPrint(map); int[] array = new int[] { 5, 7 }; debugPrint(array); ArrayList<Integer> arrayList = new ArrayList<>(2); arrayList.add(5); arrayList.add(7); debugPrint(arrayList); Collection<Integer> collection = new HashSet<>(2); collection.add(5); collection.add(7); debugPrint(collection); Object object = new Object(); debugPrint(object); Map<String, String> map1 = new HashMap<>(); map1.put("a", "hello"); map1.put("b", "goodbye"); Object[] array2 = new Object[] { 17, "yes", "no", map1 }; Map<String, Object> map2 = new HashMap<>(); map2.put("first", 5.4); map2.put("second", array2); map2.put("third", map1); debugPrint(map2); class MyBean { @SuppressWarnings("unused") public int getX() { return 11; } @SuppressWarnings("unused") public boolean isHot() { return true; } @SuppressWarnings("unused") public String getName() { return "yellow"; } } debugPrint(new MyBean()); }
From source file:net.itransformers.snmp2xml4j.snmptoolkit.XsltExecutor.java
/** * <p>main.</p>/*from w w w .java 2s . c om*/ * * @param args an array of {@link java.lang.String} objects. * @throws java.io.IOException if any. */ public static void main(String[] args) throws IOException { if (args.length != 3 && args.length != 4) { System.out.println("Missing input parameters"); System.out.println( " Example usage: xsltTransform.sh /home/test/test.xslt /usr/data/Input.xml /usr/data/Output.xml "); return; } String inputXslt = args[0]; if (inputXslt == null) { System.out.println("Missing input xslt file path"); System.out.println( " Example usage: xsltTransformer.sh /home/test/test.xslt /usr/data/Input.xml /usr/data/Output.xml"); return; } String inputFilePath = args[1]; if (inputFilePath == null) { System.out.println("Missing input xml file path"); System.out.println( " Example usage: xsltTransformer.sh /home/test/test.xslt /usr/data/Input.xml /usr/data/Output.xml"); return; } String outputFilePath = args[2]; if (outputFilePath == null) { System.out.println("Missing output file path"); System.out.println( " Example usage: xsltTransformer.sh /home/test/test.xslt /usr/data/Input.xml /usr/data/Output.xml"); return; } Map params = new HashMap<String, String>(); if (args.length == 4) { String deviceOS = args[3]; if (deviceOS != null) { params.put("DeviceOS", deviceOS); } } ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); File xsltFileName1 = new File(inputXslt); FileInputStream inputStream1 = new FileInputStream(new File(inputFilePath)); XsltTransformer xsltTransformer = new XsltTransformer(); try { xsltTransformer.transformXML(inputStream1, xsltFileName1, outputStream1, params); } catch (TransformerException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } FileUtils.writeStringToFile(new File(outputFilePath), new String(outputStream1.toByteArray())); System.out.println("Done! please review the transformed file " + outputFilePath); }
From source file:com.gzj.tulip.jade.statement.SystemInterpreter.java
public static void main(String[] args) throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("table", "my_table_name"); parameters.put("id", "my_id"); parameters.put(":1", "first_param"); final Pattern PATTERN = Pattern.compile("\\{([a-zA-Z0-9_\\.\\:]+)\\}|##\\((.+)\\)"); String sql = "select form ##(:table) {name} where {id}='{1}'"; StringBuilder sb = new StringBuilder(sql.length() + 200); Matcher matcher = PATTERN.matcher(sql); int start = 0; while (matcher.find(start)) { sb.append(sql.substring(start, matcher.start())); String group = matcher.group(); String key = null;//w w w . j av a 2 s. c om if (group.startsWith("{")) { key = matcher.group(1); } else if (group.startsWith("##(")) { key = matcher.group(2); } System.out.println(key); if (key == null || key.length() == 0) { continue; } Object value = parameters.get(key); // {paramName}?{:1}? if (value == null) { if (key.startsWith(":") || key.startsWith("$")) { value = parameters.get(key.substring(1)); // {:paramName} } else { char ch = key.charAt(0); if (ch >= '0' && ch <= '9') { value = parameters.get(":" + key); // {1}? } } } if (value == null) { value = parameters.get(key); // ? } if (value != null) { sb.append(value); } else { sb.append(group); } start = matcher.end(); } sb.append(sql.substring(start)); System.out.println(sb); }
From source file:jmxbf.java
public static void main(String[] args) throws IOException, MalformedObjectNameException { String HOST = ""; String PORT = ""; String usersFile = ""; String pwdFile = ""; CommandLine cmd = getParsedCommandLine(args); if (cmd != null) { HOST = cmd.getOptionValue("host"); PORT = cmd.getOptionValue("port"); usersFile = cmd.getOptionValue("usernames-file"); pwdFile = cmd.getOptionValue("passwords-file"); } else {/* w ww .ja v a 2 s. c om*/ System.exit(1); } String finalResults = ""; BufferedReader users = new BufferedReader(new FileReader(usersFile)); BufferedReader pwds = new BufferedReader(new FileReader(pwdFile)); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + HOST + ":" + PORT + "/jmxrmi"); //new JMXServiceURL("service:jmx:remoting-jmx://" + HOST + ":" + PORT); String user = null; boolean found = false; while ((user = users.readLine()) != null) { String pwd = null; while ((pwd = pwds.readLine()) != null) { //System.out.println(user+":"+pwd); Map<String, String[]> env = new HashMap<>(); String[] credentials = { user, pwd }; env.put(JMXConnector.CREDENTIALS, credentials); try { JMXConnector jmxConnector = JMXConnectorFactory.connect(url, env); System.out.println(); System.out.println(); System.out.println(); System.out.println( "[+] ###SUCCESS### - We got a valid connection for: " + user + ":" + pwd + "\r\n\r\n"); finalResults = finalResults + "\n" + user + ":" + pwd; jmxConnector.close(); found = true; break; } catch (java.lang.SecurityException e) { System.out.println("Auth failed!!!\r\n"); } } if (found) { System.out.println("Found some valid credentials - continuing brute force"); found = false; } //closing and reopening pwds pwds.close(); pwds = new BufferedReader(new FileReader(pwdFile)); } users.close(); //print final results if (finalResults.length() != 0) { System.out.println("The following valid credentials were found:\n"); System.out.println(finalResults); } }
From source file:edu.uchicago.mpcs.CrimeTopology.CrimeTopology.java
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException { Map stormConf = Utils.readStormConfig(); String zookeepers = StringUtils.join((List<String>) (stormConf.get("storm.zookeeper.servers")), ","); System.out.println(zookeepers); ZkHosts zkHosts = new ZkHosts(zookeepers); SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, "siruif-crime", "/siruif-crime", "crime_id"); kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); kafkaConfig.zkServers = (List<String>) stormConf.get("storm.zookeeper.servers"); kafkaConfig.zkRoot = "/siruif-crime"; kafkaConfig.zkPort = 2181;/*from ww w. j a v a2s . c o m*/ KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("raw-siruif-crime", kafkaSpout, 1); builder.setBolt("filter-siruif-crime", new FilterCrimeBolt(), 1).shuffleGrouping("raw-siruif-crime"); builder.setBolt("extract-siruif-ward", new UpdateCrimeBolt(), 1).fieldsGrouping("filter-siruif-crime", new Fields("ward")); Map conf = new HashMap(); conf.put(backtype.storm.Config.TOPOLOGY_WORKERS, 2); if (args != null && args.length > 0) { StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { conf.put(backtype.storm.Config.TOPOLOGY_DEBUG, true); LocalCluster cluster = new LocalCluster(zookeepers, 2181L); cluster.submitTopology("siruif-crime-topology", conf, builder.createTopology()); } }
From source file:common.ReverseWordsCount.java
public static void main(String[] args) throws IOException { List<String> readLines = FileUtils.readLines(new File("G:\\\\LTNMT\\LTNMT\\sougou\\sougou2500.txt")); Map<String, Integer> words = new HashMap<>(); for (String line : readLines) { String[] split = line.split(" "); for (String wprd : split) { Integer get = words.get(wprd); if (get == null) { words.put(wprd, 1); } else { words.put(wprd, get + 1); }// w ww .j a v a 2 s . c o m } } Set<Map.Entry<String, Integer>> entrySet = words.entrySet(); List<Map.Entry<String, Integer>> reverseLists = new ArrayList<>(entrySet); Collections.sort(reverseLists, new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return o2.getValue().compareTo(o1.getValue()); } }); PrintStream ps = new PrintStream("c:/reverseWords.txt"); for (Map.Entry<String, Integer> teEntry : reverseLists) { ps.println(teEntry.getKey() + " " + teEntry.getValue()); } ps.close(); }