List of usage examples for java.util Map keySet
Set<K> keySet();
From source file:com.yahoo.athenz.example.instance.InstanceClientRegister.java
public static void main(String[] args) throws MalformedURLException, IOException { // parse our command line to retrieve required input CommandLine cmd = parseCommandLine(args); String domainName = cmd.getOptionValue("domain").toLowerCase(); String serviceName = cmd.getOptionValue("service").toLowerCase(); String provider = cmd.getOptionValue("provider").toLowerCase(); String instance = cmd.getOptionValue("instance"); String dnsSuffix = cmd.getOptionValue("dnssuffix"); String providerKeyPath = cmd.getOptionValue("providerkey"); String providerKeyId = cmd.getOptionValue("providerkeyid"); String instanceKeyPath = cmd.getOptionValue("instancekey"); String ztsUrl = cmd.getOptionValue("ztsurl"); // get our configured private key PrivateKey providerKey = Crypto.loadPrivateKey(new File(providerKeyPath)); // first we are going to generate our attestation data // which we are going to use jwt. ZTS Server will send // this object to the specified provider for validation String compactJws = Jwts.builder().setSubject(domainName + "." + serviceName).setIssuer(provider) .setAudience("zts").setId(instance) .setExpiration(/*from w ww. ja v a 2 s .c om*/ new Date(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES))) .setHeaderParam("keyId", providerKeyId).signWith(SignatureAlgorithm.RS256, providerKey).compact(); System.out.println("JWS: \n" + compactJws + "\n"); // now we need to generate our CSR so we can get // a TLS certificate for our instance PrivateKey instanceKey = Crypto.loadPrivateKey(new File(instanceKeyPath)); String csr = generateCSR(domainName, serviceName, instance, dnsSuffix, instanceKey); if (csr == null) { System.err.println("Unable to generate CSR for instance"); System.exit(1); } System.out.println("CSR: \n" + csr + "\n"); // now let's generate our instance register object that will be sent // to the ZTS Server InstanceRegisterInformation info = new InstanceRegisterInformation().setAttestationData(compactJws) .setDomain(domainName).setService(serviceName).setProvider(provider).setToken(true).setCsr(csr); // now contact zts server to request identity for instance InstanceIdentity identity = null; Map<String, List<String>> responseHeaders = new HashMap<>(); try (ZTSClient ztsClient = new ZTSClient(ztsUrl)) { identity = ztsClient.postInstanceRegisterInformation(info, responseHeaders); } catch (ZTSClientException ex) { System.out.println("Unable to register instance: " + ex.getMessage()); System.exit(2); } System.out.println("Identity TLS Certificate: \n" + identity.getX509Certificate()); Map<String, String> attrs = identity.getAttributes(); if (attrs != null) { System.out.println("Provider Attributes:"); for (String key : attrs.keySet()) { System.out.println("\t" + key + ": " + attrs.get(key)); } } }
From source file:importer.handler.post.stages.Splitter.java
/** test and commandline utility */ public static void main(String[] args) { if (args.length >= 1) { try {//from w ww.j a v a 2 s . co m int i = 0; int fileIndex = 0; // see if the user supplied a conf file String textConf = Discriminator.defaultConf; while (i < args.length) { if (args[i].equals("-c") && i < args.length - 1) { textConf = readConfig(args[i + 1]); i += 2; } else { fileIndex = i; i++; } } File f = new File(args[fileIndex]); char[] data = new char[(int) f.length()]; FileReader fr = new FileReader(f); fr.read(data); JSONObject config = (JSONObject) JSONValue.parse(textConf); Splitter split = new Splitter(config); Map<String, String> map = split.split(new String(data)); Set<String> keys = map.keySet(); String rawFileName = args[fileIndex]; int pos = rawFileName.lastIndexOf("."); if (pos != -1) rawFileName = rawFileName.substring(0, pos); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String key = iter.next(); String fName = rawFileName + "-" + key + ".xml"; File g = new File(fName); if (g.exists()) g.delete(); FileOutputStream fos = new FileOutputStream(g); fos.write(map.get(key).getBytes("UTF-8")); fos.close(); } } catch (Exception e) { e.printStackTrace(System.out); } } else System.out.println("usage: java -jar split.jar [-c json-config] <tei-xml>\n"); }
From source file:LogTest.java
public static void main(String[] args) throws IOException { String inputfile = args[0];/* w ww . ja v a 2s .c o m*/ String outputfile = args[1]; Map<String, Integer> map = new TreeMap<String, Integer>(); Scanner scanner = new Scanner(new File(inputfile)); while (scanner.hasNext()) { String word = scanner.next(); Integer count = map.get(word); count = (count == null ? 1 : count + 1); map.put(word, count); } scanner.close(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); PrintWriter out = new PrintWriter(new FileWriter(outputfile)); for (String key : keys) out.println(key + " : " + map.get(key)); out.close(); }
From source file:com.zimbra.cs.mailbox.Metadata.java
public static void main(String[] args) throws MailServiceException { String encoded = "d1:ai1e4:aclmd1:gld1:ei0e1:g36:474b7021-cef6-469d-b5fb-54c96117efd11:ri1e1:ti1eee2:gei0e2:iei0ee5:mdveri4e4:mseqi628e2:szi7596456e4:unxti744e1:vi10e2:vti5ee"; Metadata meta = new Metadata(encoded); Map<String, ?> map = meta.asMap(); for (String key : map.keySet()) { System.out.println("key: " + key + " value: " + map.get(key)); }//from w ww . jav a 2 s .c om }
From source file:com.hesine.manager.generate.Generate.java
public static void main(String[] args) throws Exception { File projectPath = new DefaultResourceLoader().getResource("").getFile(); // Generate.execute(projectPath); // /* w ww . ja v a 2s. c om*/ String packageName = "com.hesine.manager"; String moduleName = ""; // ? List<Map<String, String>> list = DBOperator.getTables("tb_"); for (Map<String, String> a : list) { System.out.println(a.toString()); if (a.get("tableName").equals("tb_userinfo")) { List<Map<String, String>> listTC = DBOperator.getTableColumns(a.get("tableName")); // ? for (Map<String, String> b : listTC) { System.out.println(b.toString()); for (String key : b.keySet()) { System.out.println(key + " : " + b.get(key)); } } Generate.execute(projectPath, packageName, moduleName, a, listTC); break; } } }
From source file:com.di.bi.nextgen.installattribution.searchcountrycode.SearchCountryCode.java
public static void main(String[] args) throws Exception { Map<String, String> map = CSVReader(); List<String> miss = new ArrayList<>(); List<String[]> data = new ArrayList<>(); String csv = "infinity.csv"; CSVWriter writer = new CSVWriter(new FileWriter(csv)); List<String[]> outList = new ArrayList<>(); JSONArray arry = ReadJson();//from w w w .j a v a2s .c o m for (String key : map.keySet()) { String[] arr = key.split(";"); boolean isf = false; for (int i = 0; i < arry.length(); ++i) { JSONObject o = arry.getJSONObject(i); if (arr.length > 1) { if (o.keySet().contains(arr[1].toUpperCase())) { System.out.println("arr[]1" + arr[1]); System.out.println("o.keySet() " + o.keySet()); System.out.println(" bu " + o.keySet().contains(arr[1].toUpperCase())); JSONArray arryC = o.getJSONArray(arr[1].toUpperCase()); for (int j = 0; j < arryC.length(); ++j) { String[] tmp = { map.get(key) + "," + key + ";" + arryC.getString(j) }; outList.add(tmp); } isf = true; break; } } } if (!isf) { miss.add(key); isf = false; } } writer.writeAll(outList); writer.close(); System.out.println("Miissing" + miss); }
From source file:com.joliciel.talismane.terminology.TalismaneTermExtractorMain.java
public static void main(String[] args) throws Exception { String termFilePath = null;/*ww w.j ava2s. co m*/ String outFilePath = null; Command command = Command.extract; int depth = -1; String databasePropertiesPath = null; String projectCode = null; String terminologyPropertiesPath = null; Map<String, String> argMap = StringUtils.convertArgs(args); String logConfigPath = argMap.get("logConfigFile"); if (logConfigPath != null) { argMap.remove("logConfigFile"); Properties props = new Properties(); props.load(new FileInputStream(logConfigPath)); PropertyConfigurator.configure(props); } Map<String, String> innerArgs = new HashMap<String, String>(); for (Entry<String, String> argEntry : argMap.entrySet()) { String argName = argEntry.getKey(); String argValue = argEntry.getValue(); if (argName.equals("command")) command = Command.valueOf(argValue); else if (argName.equals("termFile")) termFilePath = argValue; else if (argName.equals("outFile")) outFilePath = argValue; else if (argName.equals("depth")) depth = Integer.parseInt(argValue); else if (argName.equals("databaseProperties")) databasePropertiesPath = argValue; else if (argName.equals("terminologyProperties")) terminologyPropertiesPath = argValue; else if (argName.equals("projectCode")) projectCode = argValue; else innerArgs.put(argName, argValue); } if (termFilePath == null && databasePropertiesPath == null) throw new TalismaneException("Required argument: termFile or databasePropertiesPath"); if (termFilePath != null) { String currentDirPath = System.getProperty("user.dir"); File termFileDir = new File(currentDirPath); if (termFilePath.lastIndexOf("/") >= 0) { String termFileDirPath = termFilePath.substring(0, termFilePath.lastIndexOf("/")); termFileDir = new File(termFileDirPath); termFileDir.mkdirs(); } } long startTime = new Date().getTime(); try { if (command.equals(Command.analyse)) { innerArgs.put("command", "analyse"); } else { innerArgs.put("command", "process"); } String sessionId = ""; TalismaneServiceLocator locator = TalismaneServiceLocator.getInstance(sessionId); TalismaneService talismaneService = locator.getTalismaneService(); TalismaneConfig config = talismaneService.getTalismaneConfig(innerArgs, sessionId); TerminologyServiceLocator terminologyServiceLocator = TerminologyServiceLocator.getInstance(locator); TerminologyService terminologyService = terminologyServiceLocator.getTerminologyService(); TerminologyBase terminologyBase = null; if (projectCode == null) throw new TalismaneException("Required argument: projectCode"); File file = new File(databasePropertiesPath); FileInputStream fis = new FileInputStream(file); Properties dataSourceProperties = new Properties(); dataSourceProperties.load(fis); terminologyBase = terminologyService.getPostGresTerminologyBase(projectCode, dataSourceProperties); TalismaneSession talismaneSession = talismaneService.getTalismaneSession(); if (command.equals(Command.analyse) || command.equals(Command.extract)) { Locale locale = talismaneSession.getLocale(); Map<TerminologyProperty, String> terminologyProperties = new HashMap<TerminologyProperty, String>(); if (terminologyPropertiesPath != null) { Map<String, String> terminologyPropertiesStr = StringUtils.getArgMap(terminologyPropertiesPath); for (String key : terminologyPropertiesStr.keySet()) { try { TerminologyProperty property = TerminologyProperty.valueOf(key); terminologyProperties.put(property, terminologyPropertiesStr.get(key)); } catch (IllegalArgumentException e) { throw new TalismaneException("Unknown terminology property: " + key); } } } else { terminologyProperties = getDefaultTerminologyProperties(locale); } if (depth <= 0 && !terminologyProperties.containsKey(TerminologyProperty.maxDepth)) throw new TalismaneException("Required argument: depth"); InputStream regexInputStream = getInputStreamFromResource( "parser_conll_with_location_input_regex.txt"); Scanner regexScanner = new Scanner(regexInputStream, "UTF-8"); String inputRegex = regexScanner.nextLine(); regexScanner.close(); config.setInputRegex(inputRegex); Charset outputCharset = config.getOutputCharset(); TermExtractor termExtractor = terminologyService.getTermExtractor(terminologyBase, terminologyProperties); if (depth > 0) termExtractor.setMaxDepth(depth); termExtractor.setOutFilePath(termFilePath); if (outFilePath != null) { if (outFilePath.lastIndexOf("/") >= 0) { String outFileDirPath = outFilePath.substring(0, outFilePath.lastIndexOf("/")); File outFileDir = new File(outFileDirPath); outFileDir.mkdirs(); } File outFile = new File(outFilePath); outFile.delete(); outFile.createNewFile(); Writer writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(outFilePath), outputCharset)); TermAnalysisWriter termAnalysisWriter = new TermAnalysisWriter(writer); termExtractor.addTermObserver(termAnalysisWriter); } Talismane talismane = config.getTalismane(); talismane.setParseConfigurationProcessor(termExtractor); talismane.process(); } else if (command.equals(Command.list)) { List<Term> terms = terminologyBase.findTerms(2, null, 0, null, null); for (Term term : terms) { LOG.debug("Term: " + term.getText()); LOG.debug("Frequency: " + term.getFrequency()); LOG.debug("Heads: " + term.getHeads()); LOG.debug("Expansions: " + term.getExpansions()); LOG.debug("Contexts: " + term.getContexts()); } } } finally { long endTime = new Date().getTime(); long totalTime = endTime - startTime; LOG.info("Total time: " + totalTime); } }
From source file:org.eclipseplugins.impexeditor.http.ImpexHttpClient.java
public static void main(final String[] args) throws Exception { final ImpexHttpClient impexHttpClient = new ImpexHttpClient("http://localhost:9001/hac"); final long startTime = System.currentTimeMillis(); final Map<String, JsonArray> allatypes = new HashMap<String, JsonArray>(); for (final JsonValue type : impexHttpClient.getAllTypes()) { allatypes.put(type.asString(),/*from ww w . ja v a 2s. c o m*/ impexHttpClient.getTypeandAttribute(type.asString()).get("attributes").asArray()); } for (final String type : allatypes.keySet()) { System.out.println("type :" + type); for (final JsonValue string : allatypes.get(type)) { System.out.println("---- " + string.asString()); } } final long stopTime = System.currentTimeMillis(); final long elapsedTime = stopTime - startTime; System.out.println("Success elapsed time in seconde " + TimeUnit.MILLISECONDS.toSeconds(elapsedTime)); }
From source file:com.mmounirou.spotirss.SpotiRss.java
/** * @param args/* w w w.java2 s.c om*/ * @throws IOException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws SpotifyClientException * @throws ChartRssException * @throws SpotifyException */ public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SpotifyClientException { if (args.length == 0) { System.err.println("usage : java -jar spotiboard.jar <charts-folder>"); return; } Properties connProperties = new Properties(); InputStream inStream = SpotiRss.class.getResourceAsStream("/spotify-server.properties"); try { connProperties.load(inStream); } finally { IOUtils.closeQuietly(inStream); } String host = connProperties.getProperty("host"); int port = Integer.parseInt(connProperties.getProperty("port")); String user = connProperties.getProperty("user"); final SpotifyClient spotifyClient = new SpotifyClient(host, port, user); final Map<String, Playlist> playlistsByTitle = getPlaylistsByTitle(spotifyClient); final File outputDir = new File(args[0]); outputDir.mkdirs(); TrackCache cache = new TrackCache(); try { for (String strProvider : PROVIDERS) { String providerClassName = EntryToTrackConverter.class.getPackage().getName() + "." + StringUtils.capitalize(strProvider); final EntryToTrackConverter converter = (EntryToTrackConverter) SpotiRss.class.getClassLoader() .loadClass(providerClassName).newInstance(); Iterable<String> chartsRss = getCharts(strProvider); final File resultDir = new File(outputDir, strProvider); resultDir.mkdir(); final SpotifyHrefQuery hrefQuery = new SpotifyHrefQuery(cache); Iterable<String> results = FluentIterable.from(chartsRss).transform(new Function<String, String>() { @Override @Nullable public String apply(@Nullable String chartRss) { try { long begin = System.currentTimeMillis(); ChartRss bilboardChartRss = ChartRss.getInstance(chartRss, converter); Map<Track, String> trackHrefs = hrefQuery.getTrackHrefs(bilboardChartRss.getSongs()); String strTitle = bilboardChartRss.getTitle(); File resultFile = new File(resultDir, strTitle); List<String> lines = Lists.newLinkedList(FluentIterable.from(trackHrefs.keySet()) .transform(Functions.toStringFunction())); lines.addAll(trackHrefs.values()); FileUtils.writeLines(resultFile, Charsets.UTF_8.displayName(), lines); Playlist playlist = playlistsByTitle.get(strTitle); if (playlist != null) { playlist.getTracks().clear(); playlist.getTracks().addAll(trackHrefs.values()); spotifyClient.patch(playlist); LOGGER.info(String.format("%s chart exported patched", strTitle)); } LOGGER.info(String.format("%s chart exported in %s in %d s", strTitle, resultFile.getAbsolutePath(), (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - begin))); } catch (Exception e) { LOGGER.error(String.format("fail to export %s charts", chartRss), e); } return ""; } }); // consume iterables Iterables.size(results); } } finally { cache.close(); } }
From source file:org.apache.s4.adapter.Adapter.java
public static void main(String args[]) { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(/*from w w w. jav a 2 s. co m*/ OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map listenerBeanMap = appContext.getBeansOfType(EventProducer.class); if (listenerBeanMap.size() == 0) { System.err.println("No user-defined listener beans"); System.exit(1); } EventProducer[] eventListeners = new EventProducer[listenerBeanMap.size()]; int index = 0; for (Iterator it = listenerBeanMap.keySet().iterator(); it.hasNext(); index++) { String beanName = (String) it.next(); System.out.println("Adding producer " + beanName); eventListeners[index] = (EventProducer) listenerBeanMap.get(beanName); } adapter.setEventListeners(eventListeners); }