List of usage examples for org.apache.commons.lang StringUtils split
public static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified.
From source file:SplitString.java
public static void main(String[] args) { //Split a String into an Array using # as seperator. String[] splitArr = StringUtils.split("AB#CD#EF#GH", "#"); for (int i = 0; i < splitArr.length; i++) { System.out.println(i + ") " + splitArr[i]); }/*from w ww. j a va 2 s. co m*/ }
From source file:com.twitter.distributedlog.messaging.ConsoleProxyRRMultiWriter.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;//from w w w. j a va 2 s. com } String finagleNameStr = args[0]; final String streamList = args[1]; DistributedLogClient client = DistributedLogClientBuilder.newBuilder() .clientId(ClientId.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true) .finagleNameStr(finagleNameStr).build(); String[] streamNameList = StringUtils.split(streamList, ','); RRMultiWriter<Integer, String> writer = new RRMultiWriter(streamNameList, client); // Setup Terminal Terminal terminal = Terminal.setupTerminal(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { writer.write(line).addEventListener(new FutureEventListener<DLSN>() { @Override public void onFailure(Throwable cause) { System.out.println("Encountered error on writing data"); cause.printStackTrace(System.err); Runtime.getRuntime().exit(0); } @Override public void onSuccess(DLSN value) { // done } }); } client.close(); }
From source file:dpfmanager.shell.core.util.VersionUtil.java
public static void main(String[] args) { String version = args[0];//from w ww. ja va2 s . c o m String baseDir = args[1]; String issPath = baseDir + "/package/windows/DPF Manager.iss"; String rpmPath = baseDir + "/package/linux/DPFManager.old.spec"; String propOutput = baseDir + "/target/classes/version.properties"; try { // Windows iss File issFile = new File(issPath); String issContent = FileUtils.readFileToString(issFile); String newIssContent = replaceLine(StringUtils.split(issContent, '\n'), "AppVersion=", version); if (!newIssContent.isEmpty()) { FileUtils.writeStringToFile(issFile, newIssContent); System.out.println("New version information updated! (iss)"); } // RPM spec File rpmFile = new File(rpmPath); String rpmContent = FileUtils.readFileToString(rpmFile); String newRpmContent = replaceLine(StringUtils.split(rpmContent, '\n'), "Version: ", version); if (!newRpmContent.isEmpty()) { FileUtils.writeStringToFile(rpmFile, newRpmContent); System.out.println("New version information updated! (spec)"); } // Java properties file OutputStream output = new FileOutputStream(propOutput); Properties prop = new Properties(); prop.setProperty("version", version); prop.store(output, "Version autoupdated"); output.close(); System.out.println("New version information updated! (properties)"); } catch (Exception e) { System.out.println("Exception ocurred, no version changed."); e.printStackTrace(); } }
From source file:com.twitter.distributedlog.basic.MultiReader.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;/*from w ww. j a va2 s . c o m*/ } String dlUriStr = args[0]; final String streamList = args[1]; URI uri = URI.create(dlUriStr); DistributedLogConfiguration conf = new DistributedLogConfiguration(); DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder().conf(conf).uri(uri).build(); String[] streamNameList = StringUtils.split(streamList, ','); DistributedLogManager[] managers = new DistributedLogManager[streamNameList.length]; for (int i = 0; i < managers.length; i++) { String streamName = streamNameList[i]; // open the dlm System.out.println("Opening log stream " + streamName); managers[i] = namespace.openLog(streamName); } final CountDownLatch keepAliveLatch = new CountDownLatch(1); for (DistributedLogManager dlm : managers) { final DistributedLogManager manager = dlm; dlm.getLastLogRecordAsync().addEventListener(new FutureEventListener<LogRecordWithDLSN>() { @Override public void onFailure(Throwable cause) { if (cause instanceof LogNotFoundException) { System.err.println( "Log stream " + manager.getStreamName() + " is not found. Please create it first."); keepAliveLatch.countDown(); } else if (cause instanceof LogEmptyException) { System.err.println("Log stream " + manager.getStreamName() + " is empty."); readLoop(manager, DLSN.InitialDLSN, keepAliveLatch); } else { System.err.println("Encountered exception on process stream " + manager.getStreamName()); keepAliveLatch.countDown(); } } @Override public void onSuccess(LogRecordWithDLSN record) { readLoop(manager, record.getDlsn(), keepAliveLatch); } }); } keepAliveLatch.await(); for (DistributedLogManager dlm : managers) { dlm.close(); } namespace.close(); }
From source file:com.twitter.distributedlog.basic.ConsoleProxyMultiWriter.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;/*from ww w . ja v a2 s .c om*/ } String finagleNameStr = args[0]; final String streamList = args[1]; DistributedLogClient client = DistributedLogClientBuilder.newBuilder() .clientId(ClientId.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true) .finagleNameStr(finagleNameStr).build(); String[] streamNameList = StringUtils.split(streamList, ','); DistributedLogMultiStreamWriter multiStreamWriter = DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList(streamNameList)).bufferSize(0).client(client).flushIntervalMs(0) .firstSpeculativeTimeoutMs(10000).maxSpeculativeTimeoutMs(20000).requestTimeoutMs(50000).build(); // Setup Terminal Terminal terminal = Terminal.setupTerminal(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() { @Override public void onFailure(Throwable cause) { System.out.println("Encountered error on writing data"); cause.printStackTrace(System.err); Runtime.getRuntime().exit(0); } @Override public void onSuccess(DLSN value) { // done } }); } multiStreamWriter.close(); client.close(); }
From source file:name.milesparker.gerrit.analysis.CollectGit.java
public static void main(String[] args) { String gitDirectory = args[0]; String dataDirectory = args[1]; String[] projects = StringUtils.split(args[2], ","); deleteContents(dataDirectory);/*ww w. j av a 2 s . co m*/ collectStats(gitDirectory, dataDirectory, projects); formatFiles(dataDirectory); cocatenate(dataDirectory, projects); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step5LinguisticPreprocessing.java
public static void main(String[] args) throws Exception { // input dir - list of xml query containers // step4-boiler-plate/ File inputDir = new File(args[0]); // output dir File outputDir = new File(args[1]); if (!outputDir.exists()) { outputDir.mkdirs();//from ww w. j a va2 s.c om } // iterate over query containers for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { // System.out.println(rankedResults.plainText); if (rankedResults.plainText != null) { String[] lines = StringUtils.split(rankedResults.plainText, "\n"); // collecting all cleaned lines List<String> cleanLines = new ArrayList<>(lines.length); // collecting line tags List<String> lineTags = new ArrayList<>(lines.length); for (String line : lines) { // get the tag String tag = null; Matcher m = OPENING_TAG_PATTERN.matcher(line); if (m.find()) { tag = m.group(1); } if (tag == null) { throw new IllegalArgumentException("No html tag found for line:\n" + line); } // replace the tag at the beginning and the end String noTagText = line.replaceAll("^<\\S+>", "").replaceAll("</\\S+>$", ""); // do some html cleaning noTagText = noTagText.replaceAll(" ", " "); noTagText = noTagText.trim(); // add to the output if (!noTagText.isEmpty()) { cleanLines.add(noTagText); lineTags.add(tag); } } if (cleanLines.isEmpty()) { // the document is empty System.err.println("Document " + rankedResults.clueWebID + " in query " + queryResultContainer.qID + " is empty"); } else { // now join them back to paragraphs String text = StringUtils.join(cleanLines, "\n"); // create JCas JCas jCas = JCasFactory.createJCas(); jCas.setDocumentText(text); jCas.setDocumentLanguage("en"); // annotate WebParagraph SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(WebParagraphAnnotator.class)); // fill the original tag information List<WebParagraph> webParagraphs = new ArrayList<>( JCasUtil.select(jCas, WebParagraph.class)); // they must be the same size as original ones if (webParagraphs.size() != lineTags.size()) { throw new IllegalStateException( "Different size of annotated paragraphs and original lines"); } for (int i = 0; i < webParagraphs.size(); i++) { WebParagraph p = webParagraphs.get(i); // get tag String tag = lineTags.get(i); p.setOriginalHtmlTag(tag); } SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(StanfordSegmenter.class, // only on existing WebParagraph annotations StanfordSegmenter.PARAM_ZONE_TYPES, WebParagraph.class.getCanonicalName())); // now convert to XMI ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); XmiCasSerializer.serialize(jCas.getCas(), byteOutputStream); // encode to base64 String encoded = new BASE64Encoder().encode(byteOutputStream.toByteArray()); rankedResults.originalXmi = encoded; } } } // and save the query to output dir File outputFile = new File(outputDir, queryResultContainer.qID + ".xml"); FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8"); System.out.println("Finished " + outputFile); } }
From source file:com.twitter.distributedlog.messaging.ConsoleProxyPartitionedMultiWriter.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;//from w w w. ja v a 2 s . c o m } String finagleNameStr = args[0]; final String streamList = args[1]; DistributedLogClient client = DistributedLogClientBuilder.newBuilder() .clientId(ClientId.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true) .finagleNameStr(finagleNameStr).build(); String[] streamNameList = StringUtils.split(streamList, ','); PartitionedWriter<Integer, String> partitionedWriter = new PartitionedWriter<Integer, String>( streamNameList, new IntPartitioner(), client); // Setup Terminal Terminal terminal = Terminal.setupTerminal(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { String[] parts = StringUtils.split(line, ':'); if (parts.length != 2) { System.out.println("Invalid input. Needs 'KEY:VALUE'"); continue; } int key; try { key = Integer.parseInt(parts[0]); } catch (NumberFormatException nfe) { System.out.println("Invalid input. Needs 'KEY:VALUE'"); continue; } String value = parts[1]; partitionedWriter.write(key, value).addEventListener(new FutureEventListener<DLSN>() { @Override public void onFailure(Throwable cause) { System.out.println("Encountered error on writing data"); cause.printStackTrace(System.err); Runtime.getRuntime().exit(0); } @Override public void onSuccess(DLSN value) { // done } }); } client.close(); }
From source file:com.npower.dm.util.ConvertMailProfile.java
/** * @param args/*from ww w. j ava2 s .com*/ */ public static void main(String[] args) throws Exception { File outputFile = new File("c:/temp/mail.xml"); FileWriter writer = new FileWriter(outputFile); File csvFile = new File("c:/temp/mail.csv"); BufferedReader reader = new BufferedReader(new FileReader(csvFile)); String line = reader.readLine(); while (line != null) { line = reader.readLine(); if (StringUtils.isEmpty(line)) { continue; } String[] cols = StringUtils.split(line, ','); Map<String, String> values = new HashMap<String, String>(); values.put("name", cols[0]); values.put("smtp.host", cols[1]); values.put("pop.host", cols[2]); writeXML(writer, values); } writer.close(); reader.close(); }
From source file:com.bsi.summer.core.dao.PropertyFilter.java
public static void main(String[] args) { System.out.println(StringUtils.split("312321321", "-").length); }