List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:edu.cmu.lti.oaqa.knn4qa.utils.QrelReader.java
public QrelReader(String fileName) throws IOException { for (String s : FileUtils.readLines(new File(fileName))) { s = s.trim();//w w w . j ava 2 s .co m if (s.isEmpty()) continue; String parts[] = s.split("\\s+"); String queryId = parts[0]; String docId = parts[2]; String rel = parts[3]; HashMap<String, String> val0 = mQrels.get(queryId); if (val0 == null) { val0 = new HashMap<String, String>(); mQrels.put(queryId, val0); } val0.put(docId, rel); } }
From source file:ch.unibas.fittingwizard.application.tools.GaussianLogModifier.java
public File removeHeadersFromCluster(File fileWithHeader) { logger.info("Removing headers from cluster from file " + fileWithHeader.getAbsolutePath()); List<String> lines; try {/*w w w. j a v a 2 s . com*/ lines = FileUtils.readLines(fileWithHeader); } catch (IOException e) { throw new RuntimeException("Could not read input file " + fileWithHeader.getAbsolutePath()); } int enteringLine = getEnteringLine(lines); int terminationLine = getTerminationLine(lines); if (enteringLine > 0 && terminationLine > 0 && terminationLine != lines.size() - 1) { createBackup(fileWithHeader); List<String> linesWithoutHeader = lines.subList(enteringLine, terminationLine + 1); try { FileUtils.writeLines(fileWithHeader, linesWithoutHeader); } catch (IOException e) { throw new RuntimeException( "Could not write file without headers. " + fileWithHeader.getAbsolutePath()); } } return fileWithHeader; }
From source file:com.fluke.application.IEODReader.java
private static void processFile(File file) throws IOException { String name = file.getName().split("\\.")[0]; name = nameMap.get(name) == null ? name : nameMap.get(name); if (name.startsWith("_") || list.contains(name.toUpperCase())) { List<String> lines = FileUtils.readLines(file); process(name, lines);//from w w w . j a v a2 s . c om } }
From source file:ch.unibas.fittingwizard.application.tools.LPunParser.java
public ArrayList<AtomType> parse(File lpunFile) { List<String> lines; try {//from ww w . ja va2s . c o m lines = FileUtils.readLines(lpunFile); } catch (IOException e) { throw new RuntimeException("Could not read file " + lpunFile.getAbsolutePath(), e); } lines = removeHeader(lines); lines = removeFooter(lines); HashMap<String, ArrayList<Integer>> atomTypePositions = new HashMap<>(); int idxCharge = 0; for (int i = 0; i + 2 < lines.size(); i += 3) { String type = lines.get(i).trim().split("\\s+")[0].trim(); ArrayList<Integer> indices = atomTypePositions.get(type); if (indices == null) { indices = new ArrayList<>(); atomTypePositions.put(type, indices); } indices.add(idxCharge); idxCharge++; } ArrayList<AtomType> charges = new ArrayList<>(); for (Map.Entry<String, ArrayList<Integer>> entry : atomTypePositions.entrySet()) { ArrayList<Integer> indices = entry.getValue(); int[] array = new int[indices.size()]; for (int i = 0; i < indices.size(); i++) array[i] = indices.get(i); AtomType atomType = new AtomType(entry.getKey(), array); charges.add(atomType); } return charges; }
From source file:com.opengamma.util.StringListFactoryBean.java
@Override protected List<String> createObject() { if (getFile() == null) { throw new IllegalArgumentException("file must be set"); }// w w w . j a va 2 s . c o m try { return FileUtils.readLines(getFile()); } catch (FileNotFoundException e) { throw new IllegalArgumentException("File not found: " + getFile(), e); } catch (IOException e) { throw new OpenGammaRuntimeException("Error while reading file: " + getFile(), e); } }
From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.ThinkingSeedGenerator.java
public static String ThinkingSeedGenerator(String seed, int difficulty, String language) throws ClassNotFoundException, SQLException, IOException, InstantiationException, IllegalAccessException {/*from w w w .j a va2 s . c om*/ ArrayList<String> mined = new ArrayList<String>(); Connect c = new Connect(language); RandomWordGenerator r = new RandomWordGenerator(c); String randomPhrase = r.selectRandomWord(seed, difficulty); int size = randomPhrase.split(",").length; Random rand = new Random(); if (language.equalsIgnoreCase("en")) { while (mined.size() < size) { int Point = rand.nextInt(1172);//number of words in english thesaurus String word = FileUtils.readLines(new File(c.getEnglish_thes())).get(Point).trim(); if (mined.contains(word)) {//|| inf.getStop().contains(word)) { continue; } mined.add(word); } } else if (language.equalsIgnoreCase("de")) { while (mined.size() < size) { int Point = rand.nextInt(1704);//number of words in german thesaurus String word = FileUtils.readLines(new File(c.getGerman_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } else { while (mined.size() < size) { int Point = rand.nextInt(933);//number of words in greek thesaurus String word = FileUtils.readLines(new File(c.getGreek_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } c.CloseConnection(); return StringUtils.join(mined, ","); }
From source file:com.gargoylesoftware.js.CodeUpdater.java
private static void processFile(final File originalFile, final boolean isMain) throws IOException { String relativePath = originalFile.getPath().replace('\\', '/'); relativePath = "com/gargoylesoftware/js/" + relativePath.substring(relativePath.indexOf("/jdk/") + "/jdk/".length()); final String root = isMain ? "src/main/java/" : "src/test/java/"; final File localFile = new File(root + relativePath); if (!localFile.exists()) { System.out.println("File doesn't locally exist: " + relativePath); return;/*from ww w . j a v a2s . c o m*/ } final List<String> originalLines = FileUtils.readLines(originalFile); final List<String> localLines = FileUtils.readLines(localFile); while (!isCodeStart(originalLines.get(0))) { originalLines.remove(0); } for (int i = 0; i < localLines.size(); i++) { if (isCodeStart(localLines.get(i))) { while (i < localLines.size()) { localLines.remove(i); } break; } } for (int i = 0; i < originalLines.size(); i++) { String line = originalLines.get(i); line = line.replace("jdk.internal.org.objectweb.asm", "org.objectweb.asm"); line = line.replace("jdk.nashorn.internal", "com.gargoylesoftware.js.nashorn.internal"); line = line.replace("jdk/nashorn/internal", "com/gargoylesoftware/js/nashorn/internal"); line = line.replace("jdk/nashorn/javaadapters", "com/gargoylesoftware/js/nashorn/javaadapters"); line = line.replace("jdk.nashorn.api", "com.gargoylesoftware.js.nashorn.api"); line = line.replace("jdk.nashorn.tools", "com.gargoylesoftware.js.nashorn.tools"); line = line.replace("jdk.internal.dynalink", "com.gargoylesoftware.js.internal.dynalink"); line = line.replace(" @Constructor", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Constructor"); line = line.replace(" @Property", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Property"); originalLines.set(i, line); if (line.equals("@jdk.Exported")) { originalLines.remove(i--); } } localLines.addAll(originalLines); FileUtils.writeLines(localFile, localLines); }
From source file:com.gs.obevo.util.FileUtilsCobra.java
public static MutableList<String> readLines(File file) { try {//from ww w . j ava 2 s . c om return FastList.newList(FileUtils.readLines(file)); } catch (IOException e) { throw new IllegalArgumentException(e); } }
From source file:cc.kave.episodes.mining.reader.FileReader.java
public List<String> readFile(File file) { assertTrue(file.exists(), "File does not exist"); assertFalse(file.isDirectory(), "File is not a file, but a directory"); List<String> lines = new LinkedList<String>(); try {/*from w ww . j a v a2s . com*/ lines = FileUtils.readLines(file); } catch (IOException e) { throw new RuntimeException(e); } return lines; }
From source file:cz.pichlik.goodsentiment.common.CSVWriterTest.java
@Test public void writeRow() throws IOException { CSVWriter writer = new CSVWriter(); writer.writeRow(asList(1, 2));/* w ww . j av a 2s . c om*/ writer.writeRow(asList(3, 4)); writer.close(); File resultFile = writer.getTemporaryResultFile(); List<String> result = FileUtils.readLines(resultFile); assertThat("Missing row", result, hasItems("1,2")); }