List of usage examples for org.apache.commons.io FileUtils readLines
public static List readLines(File file) throws IOException
From source file:de.tudarmstadt.ukp.dkpro.c4corpus.license.evaluation.LicenseDetectionEvaluation.java
public static void evaluate(String inputFile) throws IOException { List<String> lines = FileUtils.readLines(new File(inputFile)); String licenseType = "(by|by-sa|by-nd|by-nc|by-nc-sa|by-nc-nd|publicdomain)"; String noLicense = "none"; int tp = 0;// ww w . j a v a2 s . c o m int tn = 0; int fp = 0; int fn = 0; for (String line : lines) { String fileID = line.split("\t")[0]; String goldLicense = line.split("\t")[1]; String predictedLicense = line.split("\t")[2]; if (goldLicense.equalsIgnoreCase(predictedLicense)) { if (goldLicense.matches(licenseType)) { tp++; } else if (goldLicense.matches(noLicense)) { tn++; } } else { if (goldLicense.matches(noLicense) && predictedLicense.matches(licenseType)) { fp++; System.out.println("False positive detected: " + fileID); } else if (goldLicense.matches(licenseType) && predictedLicense.matches(noLicense)) { fn++; System.out.println("False negative detected: " + fileID); } } } float precision = tp / (float) (tp + fp); float recall = tp / (float) (tp + fn); float fScore = (2 * precision * recall) / (precision + recall); System.out.println("The page is licensed and predicted as licensed => True Positive: " + tp); System.out.println("The page is not licensed and not predicted as licensed => True Negative: " + tn); System.out.println( "The page has a CC link but not licensed, however predicted as licensed => False Positive: " + fp); System.out.println("The page is licensed but not predicted as licensed => False Negative: " + fn); System.out.println("====================================="); System.out.println("Precision: " + precision); System.out.println("Recall: " + recall); System.out.println("F-Score: " + fScore); }
From source file:de.atomfrede.tools.evalutation.util.PreProcessor.java
public static void replaceWhiteSpacesWithComma(File inputFile) throws IOException { List<String> inputLines = FileUtils.readLines(inputFile); List<String> outputlines = new ArrayList<String>(); for (String line : inputLines) { String outLine = line.replaceAll("\\s+", ","); outLine += "\n"; outputlines.add(outLine);//w w w . j a v a 2s . c o m } int line = 0; for (String outputLine : outputlines) { if (line == 0) FileUtils.writeStringToFile(inputFile, outputLine, false); else FileUtils.writeStringToFile(inputFile, outputLine, true); line++; } }
From source file:alilibs.AliFile.java
public static List<String> getString(String url) { File f = new File(url); try {/*from w w w. j a v a 2s . com*/ return FileUtils.readLines(f); } catch (IOException ex) { return null; } }
From source file:com.pddstudio.networkutils.utils.ArpUtils.java
/** * Reads the current ARP list and returns a List of {@link ArpInfo} instances. * @return A list of {@link ArpInfo} instances. *///from w w w . j a v a 2 s .c o m public static List<ArpInfo> fetchArpList() { List<ArpInfo> arpInfos = new LinkedList<>(); try { List<String> arpList = FileUtils.readLines(new File("/proc/net/arp")); for (String s : arpList) { Log.d("ArpUtils", "Line: " + s); String[] splitted = s.split(" +"); if (splitted[0].equals("IP")) continue; String ip = splitted[0]; String mac = splitted[3]; ArpInfo arpInfo = new ArpInfo(); arpInfo.setIpAddress(ip); arpInfo.setMacAddress(mac); arpInfos.add(arpInfo); } } catch (IOException io) { io.printStackTrace(); } return arpInfos; }
From source file:net.landora.video.filestate.DirectoryUUIDChecker.java
public static boolean validateUUID(File directory, String uuid) { try {//from ww w. ja v a 2 s .co m File uuidFile = new File(directory, UUID_FILE); if (!uuidFile.exists()) { return false; } List<String> lines = FileUtils.readLines(uuidFile); return lines.contains(uuid); } catch (Exception e) { log.error("Error checking for directory uuid: " + directory, e); return false; } }
From source file:ca.weblite.xmlvm.ConstantPoolHelper.java
/** * Loads constant pool file (e.g. constant_pool.m) into a map that maps * the integer id of the constant to a String of the c constant array. * @param file/*w ww .j a v a2s.com*/ * @return * @throws IOException */ public static Map<Integer, Constant> loadConstantPool(File file) throws IOException { Map<Integer, Constant> out = new HashMap<>(); List<String> lines = FileUtils.readLines(file); Constant currConstant = null; for (String line : lines) { if (currConstant == null && line.startsWith("// ID=") && line.indexOf(":") > 0) { String idStr = line.substring(line.indexOf("=") + 1, line.indexOf(":")); int id = Integer.parseInt(idStr); currConstant = new Constant(); currConstant.id = id; } else if (currConstant != null && line.startsWith("(JAVA_ARRAY_CHAR[]) {")) { String val = line.substring(0, line.lastIndexOf(",")); //val = val.replaceAll("\\}", ",0}"); //val = val.replaceAll("\\{,", "{"); currConstant.data = val; out.put(currConstant.id, currConstant); currConstant = null; } else if (currConstant == null && line.startsWith("// ID=")) { String idStr = line.substring(line.indexOf("=") + 1); int id = Integer.parseInt(idStr); currConstant = out.get(id); if (currConstant == null) { throw new RuntimeException( "Failed to find constant with id " + id + " in constant pool when setting length"); } } else if (currConstant != null && line.matches("^\\d+,[ ]*$")) { currConstant.len = Integer.parseInt(line.substring(0, line.indexOf(","))); currConstant = null; } } return out; }
From source file:ch.unibas.fittingwizard.application.tools.FitOutputParser.java
public double parseRmseValue(File outputFile) { List<String> lines; try {/* w ww . j a va 2s.c o m*/ lines = FileUtils.readLines(outputFile); } catch (IOException e) { throw new RuntimeException("Could not read output file.", e); } boolean lineWithRmseContained = false; Double rmse = null; for (String line : lines) { lineWithRmseContained = line.contains("RMSE:"); if (lineWithRmseContained) { rmse = Double.parseDouble(getRmseString(line)); break; } } if (!lineWithRmseContained) { throw new RuntimeException( String.format("The output file %s did not contain a RMSE line.", outputFile.getAbsoluteFile())); } return rmse; }
From source file:OpenCalaisGenerateRdfPropertiesFromWebPages.java
public OpenCalaisGenerateRdfPropertiesFromWebPages(String config_file_path, PrintWriter out) throws IOException { this.out = out; List<String> lines = (List<String>) FileUtils.readLines(new File(config_file_path)); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); try {/*from w w w . j av a 2 s . co m*/ String starting_url = scanner.next(); int spider_depth = Integer.parseInt(scanner.next()); spider(starting_url, spider_depth); } catch (Exception ex) { ex.printStackTrace(); } } this.out.close(); }
From source file:com.gargoylesoftware.htmlunit.source.Patch.java
/** * Checks the @author tag in the files touched by the specified patch. * * @param baseDir the root folder of HtmlUnit, this can be '.' if you are calling this methods from HtmlUnit code * base. If you are calling this method from another project, this specifies HtmlUnit home folder. * @param patchPath the path to the patch * @param authorName the author name, e.g. "John Smith" * @throws IOException if an exception occurs *///ww w . j ava2 s . co m public static void checkAuthor(final String baseDir, final String patchPath, final String authorName) throws IOException { final List<String> errors = new ArrayList<>(); final List<String> lines = FileUtils.readLines(new File(patchPath)); for (final String line : lines) { if (line.startsWith("+++")) { final String fileName = line.substring(4, line.indexOf('\t', 4)); if (fileName.endsWith(".java")) { final File file = new File(baseDir, fileName); if (file.exists()) { final List<String> fileLines = FileUtils.readLines(file); boolean authorFound = false; for (final String fileLine : fileLines) { if (fileLine.contains("@author " + authorName)) { authorFound = true; break; } } if (!authorFound) { System.out.println("No \"@author " + authorName + "\" in " + file.getAbsolutePath()); errors.add(file.getAbsolutePath()); } } else { System.out.println("File does not exist: " + file); } } } } if (!errors.isEmpty()) { throw new RuntimeException("Total missing files: " + errors.size()); } }
From source file:at.medevit.elexis.gdt.tools.GDTFileHelper.java
/** * Identifies a file being a GDT Satznachricht or not * /*from ww w . j a v a 2 s .c om*/ * @param file * @return boolean if file contains a SatzNachricht */ public static boolean containsSatzNachricht(File file) { try { List<String> contents = FileUtils.readLines(file); if (contents.size() == 0) return false; if (contents.get(0).substring(3, 7).equalsIgnoreCase("8000")) return true; } catch (IOException e) { return false; } return false; }