List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:de.nbi.ontology.test.OntologyMatchTest.java
/** * Test, if terms are properly match to concept labels. The a list of terms * contains a term in each line.//from w w w.j a v a 2 s .c om * * @param inFile * a list of terms * @throws IOException */ @SuppressWarnings("unchecked") @Test(dataProviderClass = TestFileProvider.class, dataProvider = "exactMatchTestFiles", groups = { "functest" }) public void exactMatch(File inFile) throws IOException { log.info("Processing " + inFile.getName()); String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath()); File outFile = new File(basename + ".out"); File resFile = new File(basename + ".res"); List<String> terms = FileUtils.readLines(inFile); PrintWriter w = new PrintWriter(new FileWriter(outFile)); for (String term : terms) { log.trace("** matching " + term); w.println(index.getExactMatches(term)); } w.flush(); w.close(); Assert.assertTrue(FileUtils.contentEquals(outFile, resFile)); }
From source file:edu.isi.pfindr.learn.util.PairsFileIO.java
public static List<Object> readDistinctElementsIntoList(String pairsFilename) { File pairsFile = new File(pairsFilename); //Set<String> distinctElementsSet = new LinkedHashSet<String>(); List<Object> distinctElementList = new ArrayList<Object>(); try {/*from w w w .j a va2 s.c o m*/ List<String> fileWithPairs = FileUtils.readLines(pairsFile); //Read one at a time to consume less memory for (String s : fileWithPairs) { //distinctElementsSet.add(s.split("\t")[0]); //distinctElementsSet.add(s.split("\t")[1]); if (!distinctElementList.contains(s.split("\t")[0])) distinctElementList.add(s.split("\t")[0]); } for (String s : fileWithPairs) { if (!distinctElementList.contains(s.split("\t")[1])) distinctElementList.add(s.split("\t")[1]); } } catch (IOException e) { System.out.println("Error while reading/writing file with pairs" + e.getMessage()); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return distinctElementList; //return new ArrayList<Object>(distinctElementsSet); }
From source file:bpsperf.modelgen.BPMNGenerator.java
public void generateModels() throws Exception { generators.add(new UserTaskSequenceGenerator()); generators.add(new ServiceTaskSequenceGenerator()); generators.add(new RestTaskSequenceGenerator()); generators.add(new ParallelServiceTasksGenerator()); generators.add(new XORModelGenerator()); File configFile = new File(confPath); List<String> lines = FileUtils.readLines(configFile); for (String line : lines) { if (!line.startsWith("#")) { generate(line);//from w ww. ja va 2 s .c om } } }
From source file:com.fluidops.iwb.api.solution.DirReferenceBasedSolutionService.java
protected File resolveReference(File directoryReference) throws IOException { List<String> lines = FileUtils.readLines(directoryReference); for (String line : lines) { if (line.startsWith("#")) continue; return new File(line); }/*from w w w. j a v a 2 s .c o m*/ throw new IOException("Invalid reference file syntax in " + directoryReference); }
From source file:edu.hawaii.soest.pacioos.text.MockDataSource.java
/** * Implements the Runnable interface, and creates a local data source server by * binding to the 127.0.0.1:5111 address. Upon a client connection, sends all lines * of the mock data file to the client./*from w ww .ja va 2 s . c om*/ * @see java.lang.Runnable#run() */ public void run() { String host = "127.0.0.1"; int portNumber = 5111; clientSocket = null; InetAddress address = null; try { address = InetAddress.getByName(host); serverSocket = new ServerSocket(portNumber, 1, address); log.info("Accepting connections on " + serverSocket.getInetAddress() + ":" + serverSocket.getLocalPort()); clientSocket = serverSocket.accept(); } catch (IOException ioe) { log.error("Couldn't open the server socket: " + ioe.getMessage()); } File ctdData = new File(mockCTDData); List<String> lines = new ArrayList<String>(); try { lines = FileUtils.readLines(ctdData); } catch (IOException e) { log.error("Couldn't read data file: " + e.getMessage()); } try { if (this.clientSocket.isConnected()) { out = new PrintWriter(clientSocket.getOutputStream(), true); // loop through the file and send each line over the wire for (String line : lines) { line = line + "\r\n"; log.debug("Line bytes: " + new String(Hex.encodeHex(line.getBytes("US-ASCII")))); out.print(line); out.flush(); Thread.sleep(500); } out.close(); } else { log.debug("Client is not connected"); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.yolodata.tbana.hadoop.mapred.splunk.inputformat.SplunkInputFormatBaseTest.java
private void testInputFormat(Configuration conf, int numberOfExpectedResults) throws Exception { boolean jobCompleted = runJob(conf); assert (jobCompleted == true); // Means that the job successfully finished String outputContent = HadoopFileTestUtils.readMapReduceOutputFile(fs, outputPath); List<String> lines = TestUtils.getLinesFromString(outputContent); int actualEvents = lines.size() - 1; //Remove one line due to header assertEquals(numberOfExpectedResults, actualEvents); List<String> expectedEndOfLines = FileUtils.readLines(new File("build/resources/test/splunkMockData.txt")); // Check that the last column of each line ends with the expected values for (int i = 0; i < lines.size(); i++) assert (lines.get(i).endsWith(expectedEndOfLines.get(i))); }
From source file:com.gargoylesoftware.htmlunit.source.JQuery173Extractor.java
/** * Generates the java code of the test cases. * @param dir the directory which holds the expectations * @throws IOException if an error occurs. *///w w w . ja va2 s .c o m public static void generateTestCases(final File dir) throws IOException { final Browser[] browsers = Browser.values(); // main browsers regardless of version e.g. FF final List<String> mainNames = new ArrayList<String>(); for (final Browser b : browsers) { final String name = b.name(); if (!"NONE".equals(name) && Character.isLetter(name.charAt(name.length() - 1))) { mainNames.add(name); } } final Map<String, List<String>> browserVersions = new HashMap<String, List<String>>(); for (final Browser b : browsers) { final String name = b.name(); for (final String mainName : mainNames) { if (!name.equals(mainName) && mainName.startsWith(name)) { List<String> list = browserVersions.get(mainName); if (list == null) { list = new ArrayList<String>(); browserVersions.put(mainName, list); } list.add(name); } } } final Map<String, List<String>> browserExpectations = new HashMap<String, List<String>>(); for (final File file : dir.listFiles()) { if (file.isFile() && file.getName().endsWith(".txt")) { for (final Browser b : browsers) { if (file.getName().equals(b.name().replace('_', '.') + ".txt")) { browserExpectations.put(b.name(), FileUtils.readLines(file)); } } } } int testNumber = 0; while (true) { final Map<String, String> testExpectation = new HashMap<String, String>(); for (final Browser b : browsers) { final String name = b.name(); if (browserExpectations.containsKey(name) && testNumber < browserExpectations.get(name).size()) { String expectation = browserExpectations.get(name).get(testNumber); if (expectation != null) { expectation = expectation.substring(expectation.indexOf('.') + 1); if (expectation.charAt(0) == ' ') { expectation = expectation.substring(1); } testExpectation.put(name, expectation.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"")); } } } if (testExpectation.isEmpty()) { break; } System.out.println(" /**"); System.out.println(" * @throws Exception if an error occurs"); System.out.println(" */"); System.out.println(" @Test"); System.out.print(" @Alerts("); boolean allSame = true; String lastExpect = null; for (final String e : testExpectation.values()) { if (lastExpect == null) { lastExpect = e; } else if (!e.equals(lastExpect)) { allSame = false; break; } } if (allSame) { final String first = testExpectation.keySet().iterator().next(); String expectation = testExpectation.get(first); if (expectation.length() > 100) { expectation = expectation.substring(0, 50) + "\"\n + \"" + expectation.substring(50); } System.out.print("\"" + expectation + '"'); } else { boolean first = true; boolean longLine = false; for (final String browser : testExpectation.keySet()) { if (!first) { System.out.print(","); if (longLine) { System.out.print("\n "); } else { System.out.print(' '); } } String expectation = testExpectation.get(browser); if (expectation.length() > 40) { expectation = expectation.substring(0, 40) + "\"\n + \"" + expectation.substring(40); longLine = true; } else { longLine = false; } System.out.print(browser + " = \"" + expectation + '"'); if (first) { first = false; } } } System.out.println(")"); if (browsers.length - 1 > testExpectation.size()) { //there are @NYI System.out.print(" @NotYetImplemented({ "); boolean first = true; for (final Browser b : browsers) { final String name = b.name(); if (!mainNames.contains(name) && !"NONE".equals(name) && !testExpectation.containsKey(name)) { if (!first) { System.out.print(", "); } System.out.print(name); if (first) { first = false; } } } System.out.println(" })"); } System.out.println(" public void test_" + (testNumber + 1) + "() throws Exception {"); System.out.println(" runTest(" + (testNumber + 1) + ");"); System.out.println(" }"); System.out.println(); testNumber++; } }
From source file:com.xiaomi.linden.lucene.analyzer.CommonMMSeg4jSegmenter.java
private void initStopWords(String stopWordsPath) { if (stopWordsPath != null) { try {/*from w ww .ja va 2 s .com*/ List<String> lines = FileUtils.readLines(new File(stopWordsPath)); Set<String> set = new HashSet<>(lines); stopWords = CharArraySet.copy(set); } catch (IOException e) { throw new RuntimeException("Read stop words failed path : " + stopWordsPath); } } }
From source file:com.igormaznitsa.mindmap.plugins.importers.Text2MindMapImporterTest.java
@Test public void testImportFromFile() throws Exception { final File file = new File(Text2MindMapImporter.class.getResource("tabbedtext.txt").getFile()); assertTrue(file.isFile());/*from ww w . ja v a2s. co m*/ final List<String> lines = FileUtils.readLines(file); final MindMap result = INSTANCE.makeFromLines(lines, null); assertEquals(5, result.getRoot().getChildren().size()); }
From source file:com.gargoylesoftware.htmlunit.general.HostTestsTest.java
private void ensure(final File file, final Set<String> set) throws IOException { final Set<String> unusedNames = new HashSet<>(set); final List<String> lines = FileUtils.readLines(file); for (final String line : lines) { for (final Iterator<String> it = unusedNames.iterator(); it.hasNext();) { if (line.contains("(\"" + it.next() + "\")")) { it.remove();/* w w w . j a va 2s .c o m*/ } } } if (!unusedNames.isEmpty()) { fail("You must specify the following line" + (unusedNames.size() == 1 ? "" : "s") + " in " + file.getName() + ":\n" + StringUtils.join(unusedNames, ", ")); } }