List of usage examples for java.util Map put
V put(K key, V value);
From source file:com.example.geomesa.kafka08.KafkaListener.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 consumer KafkaDataStore object Map<String, String> dsConf = getKafkaDataStoreConf(cmd); dsConf.put("isProducer", "false"); DataStore consumerDS = DataStoreFinder.getDataStore(dsConf); // verify that we got back our KafkaDataStore object properly if (consumerDS == null) { throw new Exception("Null consumer KafkaDataStore"); }//from w w w . j a v a 2 s. c o m // create the schema which creates a topic in Kafka // (only needs to be done once) // TODO: This should be rolled into the Command line options to make this more general. registerListeners(consumerDS); while (true) { // Wait for user to terminate with ctrl-C. } }
From source file:com.harpatec.examples.Main.java
/** * Load the Spring Integration Application Context * /*from ww w.j a v a 2s .co m*/ * @param args - command line arguments * @throws InterruptedException * @throws IOException * @throws JsonMappingException * @throws JsonGenerationException */ public static void main(final String... args) throws InterruptedException, JsonGenerationException, JsonMappingException, IOException { final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); LOGGER.debug("Dropping the collection of MessageRecords"); MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class); mongoTemplate.dropCollection(MessageRecord.class); mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("key", Order.ASCENDING).unique()); mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("completionTime", Order.ASCENDING)); RabbitTemplate inboundTemplate = (RabbitTemplate) context.getBean("amqpTemplateInbound"); Map<String, Object> messageMap = new HashMap<String, Object>(); messageMap.put("count", "4"); LOGGER.debug("Submitting first message which should pass DuplicateMessageFilter ok."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); LOGGER.debug("Submitting a duplicate message which should get caught by the DuplicateMessageFilter."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); messageMap.put("count", "0"); LOGGER.debug("Submitting a message which will not go all the way through the message flow."); submitMessage(inboundTemplate, messageMap); Thread.sleep(5 * 1000); messageMap.put("count", "1"); messageMap.put("fail", "true"); LOGGER.debug("Submitting a message which should signal that an Exception should be thrown."); submitMessage(inboundTemplate, messageMap); Thread.sleep(6 * 60 * 1000); System.exit(0); }
From source file:at.treedb.util.Execute.java
public static void main(String args[]) throws ExecuteException, IOException { String command = "-i ${source} -vcodec flv -f flv -r 25 -s 800x450 -aspect 16:9 -b 2000k -g 160 -cmp 2 -subcmp 2 -mbd 2 -trellis 2 -acodec libmp3lame -ac 2 -ar 44100 -ab 256k ${destination}"; String command2 = "-i ${source} -ss 0 -vframes 1 -vcodec mjpeg -f image2 ${destination}"; Map<String, File> map = new HashMap<String, File>(); map.put("source", new File("c:/tmp/bilder/elefant/00009.MTS")); map.put("destination", new File("c:/tmp/bilder/elefant/00009.flv")); execute("ffmpeg.exe", command.split(" "), map); map = new HashMap<String, File>(); map.put("source", new File("c:/tmp/bilder/elefant/00009.flv")); map.put("destination", new File("c:/tmp/bilder/elefant/00009.jpg")); ExecResult r = execute("ffmpeg.exe", command2.split(" "), map); System.out.println(r.exitCode); }
From source file:com.workfront.StreamClientSample.java
public static void main(String[] args) { StreamClient client = new StreamClient("http://localhost:8080/attask/api"); try {// ww w .j a v a 2 s . co m // Login System.out.print("Logging in..."); JSONObject session = client.login("admin@user.attask", "user"); System.out.println("done"); // Get user System.out.print("Retrieving user..."); JSONObject user = client.get("user", session.getString("userID"), new String[] { "ID", "homeGroupID", "emailAddr" }); System.out.println("done"); // Search projects System.out.print("Searching projects..."); Map<String, Object> map = new HashMap<String, Object>(); map.put("groupID", user.getString("homeGroupID")); JSONArray results = client.search("proj", map, new String[] { "ID", "name" }); System.out.println("done"); for (int i = 0; i < Math.min(10, results.length()); i++) { System.out.println(" - " + results.getJSONObject(i).getString("name")); } // Create project System.out.print("Creating project..."); map.clear(); map.put("name", "My Project"); map.put("groupID", user.getString("homeGroupID")); JSONObject proj = client.post("proj", map); System.out.println("done"); // Get project System.out.print("Retrieving project..."); proj = client.get("proj", proj.getString("ID")); System.out.println("done"); // Edit project System.out.print("Editing project..."); map.clear(); map.put("name", "Your Project"); proj = client.put("proj", proj.getString("ID"), map); System.out.println("done"); // Delete project System.out.print("Deleting project..."); client.delete("proj", proj.getString("ID")); System.out.println("done"); // Logout System.out.print("Logging out..."); client.logout(); System.out.println("done"); } catch (StreamClientException e) { System.out.println(e.getMessage()); } catch (JSONException e) { System.out.println(e.getMessage()); } }
From source file:com.leixl.easyframework.action.httpclient.TestHttpPost.java
public static void main(String[] args) { Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("uid", 1); paramMap.put("desc", "?????"); paramMap.put("payStatus", 1); //HttpConnUtils.postHttpContent(URL, paramMap); //HttpClient//w w w. j a v a 2 s.co m HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod(URL); // ?? NameValuePair[] data = { new NameValuePair("uid", "1"), new NameValuePair("desc", "?????"), new NameValuePair("payStatus", "1") }; // ?postMethod postMethod.setRequestBody(data); // postMethod int statusCode; try { statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK) { StringBuffer contentBuffer = new StringBuffer(); InputStream in = postMethod.getResponseBodyAsStream(); BufferedReader reader = new BufferedReader( new InputStreamReader(in, postMethod.getResponseCharSet())); String inputLine = null; while ((inputLine = reader.readLine()) != null) { contentBuffer.append(inputLine); System.out.println("input line:" + inputLine); contentBuffer.append("/n"); } in.close(); } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { // ??? Header locationHeader = postMethod.getResponseHeader("location"); String location = null; if (locationHeader != null) { location = locationHeader.getValue(); System.out.println("The page was redirected to:" + location); } else { System.err.println("Location field value is null."); } } } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:PrefsUtil.java
public static void main(String[] args) { try {/*from w w w. j ava2 s .c om*/ Map map = new HashMap(); map.put("0", "A"); map.put("1", "B"); map.put("2", "C"); map.put("3", "D"); map.put("5", "f"); Preferences prefs = Preferences.userNodeForPackage(String.class); String RECENT_FILES = "XXX"; List recentFiles = PrefsUtil.getList(prefs, RECENT_FILES); PrefsUtil.clear(prefs, RECENT_FILES); PrefsUtil.putList(prefs, recentFiles, RECENT_FILES); //System.out.println( PrefsUtil.getList( prefs, RECENT_FILES ) ); } catch (Exception e) { e.printStackTrace(); } }
From source file:httpclient.UploadAction.java
public static void main(String[] args) throws FileNotFoundException { File targetFile1 = new File("F:\\2.jpg"); // File targetFile2 = new File("F:\\1.jpg"); FileInputStream fis1 = new FileInputStream(targetFile1); // FileInputStream fis2 = new FileInputStream(targetFile2); // String targetURL = // "http://static.fangbiandian.com.cn/round_server/upload/uploadFile.do"; String targetURL = "http://www.fangbiandian.com.cn/round_server/user/updateUserInfo.do"; HttpPost filePost = new HttpPost(targetURL); try {// ww w. j a v a 2s. c o m // ????? HttpClient client = new DefaultHttpClient(); // FormBodyPart fbp1 = new FormBodyPart("file1", new // FileBody(targetFile1)); // FormBodyPart fbp2 = new FormBodyPart("file2", new // FileBody(targetFile2)); // FormBodyPart fbp3 = new FormBodyPart("file3", new // FileBody(targetFile3)); // List<FormBodyPart> picList = new ArrayList<FormBodyPart>(); // picList.add(fbp1); // picList.add(fbp2); // picList.add(fbp3); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("userId", "65478A5CD8D20C3807EE16CF22AF8A17"); Map<String, Object> map = new HashMap<String, Object>(); String jsonStr = JSON.toJSONString(paramMap); map.put("cid", 321); map.put("request", jsonStr); String jsonString = JSON.toJSONString(map); MultipartEntity multiEntity = new MultipartEntity(); Charset charset = Charset.forName("UTF-8"); multiEntity.addPart("request", new StringBody(jsonString, charset)); multiEntity.addPart("photo", new InputStreamBody(fis1, "2.jpg")); // multiEntity.addPart("licenseUrl", new InputStreamBody(fis2, // "1.jpg")); filePost.setEntity(multiEntity); HttpResponse response = client.execute(filePost); int code = response.getStatusLine().getStatusCode(); System.out.println(code); if (HttpStatus.SC_OK == code) { System.out.println("?"); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); try { // do something useful BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); String str = null; while ((str = reader.readLine()) != null) { System.out.println(str); } } finally { instream.close(); } } } else { System.out.println(""); } } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } }
From source file:com.rabbitmq.examples.FileProducer.java
public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "uri", true, "AMQP URI")); options.addOption(new Option("p", "port", true, "broker port")); options.addOption(new Option("t", "type", true, "exchange type")); options.addOption(new Option("e", "exchange", true, "exchange name")); options.addOption(new Option("k", "routing-key", true, "routing key")); CommandLineParser parser = new GnuParser(); try {//from www.j a va 2 s .c om CommandLine cmd = parser.parse(options, args); String uri = strArg(cmd, 'h', "amqp://localhost"); String exchangeType = strArg(cmd, 't', "direct"); String exchange = strArg(cmd, 'e', null); String routingKey = strArg(cmd, 'k', null); ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setUri(uri); Connection conn = connFactory.newConnection(); final Channel ch = conn.createChannel(); if (exchange == null) { System.err.println("Please supply exchange name to send to (-e)"); System.exit(2); } if (routingKey == null) { System.err.println("Please supply routing key to send to (-k)"); System.exit(2); } ch.exchangeDeclare(exchange, exchangeType); for (String filename : cmd.getArgs()) { System.out.print("Sending " + filename + "..."); File f = new File(filename); FileInputStream i = new FileInputStream(f); byte[] body = new byte[(int) f.length()]; i.read(body); i.close(); Map<String, Object> headers = new HashMap<String, Object>(); headers.put("filename", filename); headers.put("length", (int) f.length()); BasicProperties props = new BasicProperties.Builder().headers(headers).build(); ch.basicPublish(exchange, routingKey, props, body); System.out.println(" done."); } conn.close(); } catch (Exception ex) { System.err.println("Main thread caught exception: " + ex); ex.printStackTrace(); System.exit(1); } }
From source file:edu.brown.benchmark.seats.util.GenerateHistograms.java
public static void main(String[] vargs) throws Exception { ArgumentsParser args = ArgumentsParser.load(vargs); File csv_path = new File(args.getOptParam(0)); File output_path = new File(args.getOptParam(1)); GenerateHistograms gh = GenerateHistograms.generate(csv_path); Map<String, Object> m = new ListOrderedMap<String, Object>(); m.put("Airport Codes", gh.flights_per_airport.size()); m.put("Airlines", gh.flights_per_airline.getValueCount()); m.put("Departure Times", gh.flights_per_time.getValueCount()); LOG.info(StringUtil.formatMaps(m));// w w w . j a va2 s. co m System.err.println(StringUtil.join("\n", gh.flights_per_airport.keySet())); Map<String, Histogram<?>> histograms = new HashMap<String, Histogram<?>>(); histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_DEPART_TIMES, gh.flights_per_time); // histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_AIRLINE, gh.flights_per_airline); histograms.put(SEATSConstants.HISTOGRAM_FLIGHTS_PER_AIRPORT, SEATSHistogramUtil.collapseAirportFlights(gh.flights_per_airport)); for (Entry<String, Histogram<?>> e : histograms.entrySet()) { File output_file = new File(output_path.getAbsolutePath() + "/" + e.getKey() + ".histogram"); LOG.info(String.format("Writing out %s data to '%s' [samples=%d, values=%d]", e.getKey(), output_file, e.getValue().getSampleCount(), e.getValue().getValueCount())); e.getValue().save(output_file); } // FOR }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override//from w w w .jav a2s . c om public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01)); textField2.setFormatterFactory(new AbstractFormatterFactory() { @Override public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); textField2.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); double t1a1 = (((Number) textField2.getValue()).doubleValue()); if (t1a1 > 100) { textField2.setFont(new Font(attributes)); textField2.setForeground(Color.red); } else { textField2.setFont(new Font("Serif", Font.BOLD, 16)); textField2.setForeground(Color.black); } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }