List of usage examples for java.util Map put
V put(K key, V value);
From source file:com.mycompany.mavenpost.HttpTest.java
public static void main(String args[]) throws UnsupportedEncodingException, IOException { System.out.println("this is a test program"); HttpPost httppost = new HttpPost("https://app.monsum.com/api/1.0/api.php"); // Request parameters and other properties. String auth = DEFAULT_USER + ":" + DEFAULT_PASS; byte[] encodedAuth = Base64.encodeBase64(auth.getBytes()); String authHeader = "Basic " + new String(encodedAuth); //String authHeader = "Basic " +"YW5kcmVhcy5zZWZpY2hhQG1hcmtldHBsYWNlLWFuYWx5dGljcy5kZTo5MGRkYjg3NjExMWRiNjNmZDQ1YzUyMjdlNTNmZGIyYlhtMUJQQm03OHhDS1FUVm1OR1oxMHY5TVVyZkhWV3Vh"; httppost.setHeader(HttpHeaders.AUTHORIZATION, authHeader); httppost.setHeader(HttpHeaders.CONTENT_TYPE, "Content-Type: application/json"); Map<String, Object> params = new LinkedHashMap<>(); params.put("SERVICE", "customer.get"); JSONObject json = new JSONObject(); json.put("SERVICE", "customer.get"); //Map<String, Object> params2 = new LinkedHashMap<>(); //params2.put("CUSTOMER_NUMBER","5"); JSONObject array = new JSONObject(); array.put("CUSTOMER_NUMBER", "2"); json.put("FILTER", array); StringEntity param = new StringEntity(json.toString()); httppost.setEntity(param);/* ww w .ja v a2 s . c om*/ HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); System.out.println("The status code is " + statusCode); //Execute and get the response. HttpEntity entity = response.getEntity(); Header[] headers = response.getAllHeaders(); for (Header header : headers) { System.out.println("Key : " + header.getName() + " ,Value : " + header.getValue()); } if (entity != null) { String retSrc = EntityUtils.toString(entity); //Discouraged better open a stream and read the data as per Apache manual // parsing JSON //JSONObject result = new JSONObject(retSrc); Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(retSrc); String prettyJsonString = gson.toJson(je); System.out.println(prettyJsonString); } //if (entity != null) { // InputStream instream = entity.getContent(); // try { // final BufferedReader reader = new BufferedReader( // new InputStreamReader(instream)); // String line = null; // while ((line = reader.readLine()) != null) { // System.out.println(line); // } // reader.close(); // } finally { // instream.close(); // } //} }
From source file:Main.java
public static void main(String[] args) { String query = "name==p==?header=hello?aname=?????lname=lastname"; String[] params = query.split("\\?"); Map<String, String> map = new HashMap<String, String>(); for (String param : params) { String name = param.split("=")[0]; String value = param.substring(name.length(), param.length()); map.put(name, value); System.out.println(name); if (name.equals("")) { value += "?"; }//from w w w. j a v a2 s.com System.out.println(value.replaceAll(" ", "")); } }
From source file:org.bimserver.build.CreateGitHubRelease.java
public static void main(String[] args) { String username = args[0];// w w w. j av a2 s . co m String password = args[1]; String repo = args[2]; String project = args[3]; String tagname = args[4]; String name = args[5]; String body = args[6]; String draft = args[7]; String prerelease = args[8]; String filesString = args[9]; String[] filenames = filesString.split(";"); GitHubClient gitHubClient = new GitHubClient("api.github.com"); gitHubClient.setCredentials(username, password); Map<String, String> map = new HashMap<String, String>(); map.put("tag_name", tagname); // map.put("target_commitish", "test"); map.put("name", name); map.put("body", body); // map.put("draft", draft); // map.put("prerelease", prerelease); try { String string = "/repos/" + repo + "/" + project + "/releases"; System.out.println(string); JsonObject gitHubResponse = gitHubClient.post(string, map, JsonObject.class); System.out.println(gitHubResponse); String id = gitHubResponse.get("id").getAsString(); HttpHost httpHost = new HttpHost("uploads.github.com", 443, "https"); BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); basicCredentialsProvider.setCredentials(new AuthScope(httpHost), new UsernamePasswordCredentials(username, password)); HostnameVerifier hostnameVerifier = new AllowAllHostnameVerifier(); SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CloseableHttpClient client = HttpClients.custom() .setDefaultCredentialsProvider(basicCredentialsProvider) .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier).setSSLSocketFactory(sslsf) .build(); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(httpHost, basicAuth); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(basicCredentialsProvider); context.setAuthCache(authCache); for (String filename : filenames) { File file = new File(filename); String url = "https://uploads.github.com/repos/" + repo + "/" + project + "/releases/" + id + "/assets?name=" + file.getName(); HttpPost post = new HttpPost(url); post.setHeader("Accept", "application/vnd.github.manifold-preview"); post.setHeader("Content-Type", "application/zip"); post.setEntity(new InputStreamEntity(new FileInputStream(file), file.length())); HttpResponse execute = client.execute(httpHost, post, context); execute.getEntity().getContent().close(); } } catch (IOException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Map<Character, Integer> map = new TreeMap<>(); String blah = "aaaabbbbddd"; for (int i = 0; i < blah.length(); i++) { char c = blah.charAt(i); if (!map.containsKey(c)) { map.put(c, 1); } else {// w w w .j a v a 2 s .c o m map.put(c, (map.get(c) + 1)); } } for (Map.Entry<Character, Integer> entry : map.entrySet()) { System.out.print(entry.getKey() + "" + entry.getValue()); } }
From source file:MultiMap.java
public static void main(String args[]) { Map map = new HashMap(); map.put("one", "two"); map.put("three", "four"); map.put("five", "six"); MultiMap multi = new MultiMap(map); System.out.println(multi);/*w w w . j a v a2s . c o m*/ multi.add("five", "seven"); multi.add("five", "eight"); multi.add("five", "nine"); multi.add("five", "ten"); multi.add("three", "seven"); System.out.println(multi); multi.remove("three"); System.out.println(multi); }
From source file:com.pinterest.rocksplicator.Participant.java
/** * Start a Helix participant.// w ww . ja v a 2 s.co m * @param args command line parameters */ public static void main(String[] args) throws Exception { org.apache.log4j.Logger.getRootLogger().setLevel(Level.WARN); BasicConfigurator .configure(new ConsoleAppender(new PatternLayout("%d{HH:mm:ss.SSS} [%t] %-5p %30.30c - %m%n"))); CommandLine cmd = processCommandLineArgs(args); final String zkConnectString = cmd.getOptionValue(zkServer); final String clusterName = cmd.getOptionValue(cluster); final String domainName = cmd.getOptionValue(domain); final String host = cmd.getOptionValue(hostAddress); final String port = cmd.getOptionValue(hostPort); final String stateModelType = cmd.getOptionValue(stateModel); final String postUrl = cmd.getOptionValue(configPostUrl); final String instanceName = host + "_" + port; LOG.error("Starting participant with ZK:" + zkConnectString); Participant participant = new Participant(zkConnectString, clusterName, instanceName, stateModelType, Integer.parseInt(port), postUrl); HelixAdmin helixAdmin = new ZKHelixAdmin(zkConnectString); HelixConfigScope scope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT) .forCluster(clusterName).forParticipant(instanceName).build(); Map<String, String> properties = new HashMap<String, String>(); properties.put("DOMAIN", domainName + ",instance=" + instanceName); helixAdmin.setConfig(scope, properties); Thread.currentThread().join(); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.Migrator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/* w ww . jav a 2s . c o m*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output file"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(IN_EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of input EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option outClassOpt = OptionBuilder.create(OUT_EPACKAGE_CLASS); outClassOpt.setArgName("CLASS"); outClassOpt.setDescription("FQN of output EPackage implementation class"); outClassOpt.setArgs(1); outClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(outClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = URI.createFileURI(commandLine.getOptionValue(OUT)); Class<?> inClazz = Migrator.class.getClassLoader() .loadClass(commandLine.getOptionValue(IN_EPACKAGE_CLASS)); Class<?> outClazz = Migrator.class.getClassLoader() .loadClass(commandLine.getOptionValue(OUT_EPACKAGE_CLASS)); @SuppressWarnings("unused") EPackage inEPackage = (EPackage) inClazz.getMethod("init").invoke(null); EPackage outEPackage = (EPackage) outClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); Resource sourceResource = resourceSet.getResource(sourceUri, true); Resource targetResource = resourceSet.createResource(targetUri); targetResource.getContents().clear(); LOG.log(Level.INFO, "Start migration"); targetResource.getContents() .add(MigratorUtil.migrate(sourceResource.getContents().get(0), outEPackage)); LOG.log(Level.INFO, "Migration finished"); Map<String, Object> saveOpts = new HashMap<String, Object>(); saveOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saving done"); } catch (ParseException e) { showError(e.toString()); showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { showError(e.toString()); } }
From source file:at.ac.tuwien.infosys.logger.ProvisioningLogger.java
public static void main(String[] args) { Map<String, Log> deviceLogs = Collections.synchronizedMap(new HashMap<String, Log>()); System.out.println(deviceLogs.values().contains(null)); deviceLogs.put("id1", null); System.out.println(deviceLogs.values().contains(null)); }
From source file:com.alibaba.jstorm.daemon.supervisor.SandBoxMaker.java
public static void main(String[] args) { Map<Object, Object> conf = Utils.readStormConfig(); conf.put("java.sandbox.enable", Boolean.valueOf(true)); SandBoxMaker maker = new SandBoxMaker(conf); try {// www.ja va2 s . com System.out.println("sandboxPolicy:" + maker.sandboxPolicy("simple", new HashMap<String, String>())); } catch (IOException e) { e.printStackTrace(); } }
From source file:uk.ac.kcl.Main.java
public static void main(String[] args) { File folder = new File(args[0]); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File listOfFile : listOfFiles) { if (listOfFile.isFile()) { if (listOfFile.getName().endsWith(".properties")) { System.out.println("Properties sile found:" + listOfFile.getName() + ". Attempting to launch application context"); Properties properties = new Properties(); InputStream input; try { input = new FileInputStream(listOfFile); properties.load(input); if (properties.getProperty("globalSocketTimeout") != null) { TcpHelper.setSocketTimeout( Integer.valueOf(properties.getProperty("globalSocketTimeout"))); }//w ww. j ava 2 s. com Map<String, Object> map = new HashMap<>(); properties.forEach((k, v) -> { map.put(k.toString(), v); }); ConfigurableEnvironment environment = new StandardEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new MapPropertySource(listOfFile.getName(), map)); @SuppressWarnings("resource") AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.registerShutdownHook(); ctx.setEnvironment(environment); String scheduling; try { scheduling = properties.getProperty("scheduler.useScheduling"); if (scheduling.equalsIgnoreCase("true")) { ctx.register(ScheduledJobLauncher.class); ctx.refresh(); } else if (scheduling.equalsIgnoreCase("false")) { ctx.register(SingleJobLauncher.class); ctx.refresh(); SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class); launcher.launchJob(); } else if (scheduling.equalsIgnoreCase("slave")) { ctx.register(JobConfiguration.class); ctx.refresh(); } else { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (NullPointerException ex) { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (IOException e) { e.printStackTrace(); } } } } }