List of usage examples for org.apache.commons.io FileUtils lineIterator
public static LineIterator lineIterator(File file) throws IOException
File
using the default encoding for the VM. From source file:com.pieframework.model.repository.ModelStore.java
public static List<ExpressionEntry> parseInstanceFile(File file) throws IOException { List<ExpressionEntry> retList = new ArrayList<ExpressionEntry>(); LineIterator it = FileUtils.lineIterator(file); try {/*from www .j a v a 2 s . c om*/ while (it.hasNext()) { String line = it.nextLine(); if (StringUtils.startsWith(line, "#")) { // ignore comments } else { String expression = StringUtils.trimToEmpty(StringUtils.substringBefore(line, "=")); String value = StringUtils.trimToEmpty(StringUtils.substringAfter(line, "=")); if (StringUtils.isNotEmpty(expression) && StringUtils.isNotEmpty(value)) { retList.add(new ExpressionEntry().withExpression(expression).withValue(value)); } } } } finally { it.close(); } return retList; }
From source file:$.LogEventParsingIterator.java
/** * Returns a line iterator to process next/current file, opening the next file, if necessary. *//from ww w.j a va 2 s .c o m * @return line iterator for the current/next file; or null if no files left */ private LineIterator getLineIterator() throws IOException { if (lineIterator != null && lineIterator.hasNext()) { return lineIterator; } // discard current line iterator LineIterator.closeQuietly(lineIterator); lineIterator = null; if (fileEventsFound == 0) { Log.debug("No events in the last file, closing prematurely"); close(); // optimize: last file had no events, no point continuing } else if (!logFiles.isEmpty()) { File file = logFiles.poll(); Log.debug("Opening {}", file); lineIterator = FileUtils.lineIterator(file); fileEventsFound = 0; // restart per-file counter } return lineIterator; }
From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java
/** * Read static analysis output// ww w . j a v a 2s .c o m * @throws IOException * */ private static void readFromStaticAnalysisText() throws IOException { Iterator<String> lineIter = FileUtils.lineIterator(new File(dbLocation)); while (lineIter.hasNext()) { String line = lineIter.next(); String[] info = line.split("[\\s]"); String apkName = StringUtils.substringAfterLast(info[0], "/"); String seedName = info[2]; String seedType = info[3]; if (resultFromStaticAnalysis.containsKey(apkName)) { List<StaticResultBean> list = resultFromStaticAnalysis.get(apkName); list.add(new StaticResultBean(seedName, seedType)); } else { List<StaticResultBean> list = new ArrayList<StaticResultBean>(); list.add(new StaticResultBean(seedName, seedType)); resultFromStaticAnalysis.put(apkName, list); } } }
From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java
/** * //w w w .j a v a 2s. co m * @throws IOException */ private static void readFromSmartInputText() throws IOException { Iterator<String> lineIter = FileUtils.lineIterator(new File(smartInputLocation)); while (lineIter.hasNext()) { String line = lineIter.next(); String[] info = line.split(";"); String methName = info[0]; //name of the method String inputName = StringUtils.substringAfterLast(info[1], "name: "); String inputId = StringUtils.substringAfterLast(info[2], "id: "); String inputType = StringUtils.substringAfterLast(info[3], "type: "); String inputVar = StringUtils.substringAfterLast(info[4], "variations: "); String inputFlag = StringUtils.substringAfterLast(info[5], "flags: "); if (resultFromSmartInputGeneration.containsKey(methName)) { List<SmartInputBean> list = resultFromSmartInputGeneration.get(methName); list.add(new SmartInputBean(inputName, inputId, inputType, inputVar, inputFlag)); } else { List<SmartInputBean> list = new ArrayList<SmartInputBean>(); list.add(new SmartInputBean(inputName, inputId, inputType, inputVar, inputFlag)); resultFromSmartInputGeneration.put(methName, list); } } }
From source file:com.crosstreelabs.cognitio.Main.java
private void loadSeeds() throws IOException { Collection<File> seedFiles = new ArrayList<>(); if (mc.conductorSeedFiles != null && !mc.conductorSeedFiles.isEmpty()) { seedFiles = mc.conductorSeedFiles; } else {//from w ww . j a v a 2 s . c o m seedFiles.add(new File(mc.getHomeDirectory(), "seeds.txt")); } if (seedFiles.isEmpty()) { return; } final HostService hostService = injector.get(HostService.class); final CatalogueService catalogueService = injector.get(CatalogueService.class); for (File seedFile : seedFiles) { if (!seedFile.exists()) { LOGGER.warn("Seed file {} does not exist", seedFile); continue; } Iterator<String> it = FileUtils.lineIterator(seedFile); while (it.hasNext()) { String line = it.next(); if (line == null || line.trim().isEmpty() || line.trim().startsWith("#")) { continue; } line = line.trim(); io.mola.galimatias.URL url; try { url = io.mola.galimatias.URL.parse(line); } catch (GalimatiasParseException ex) { continue; } String tld = InternetDomainName.from(url.host().toString()).topPrivateDomain().toString(); Host host = hostService.findByDomain(tld); if (host == null) { host = new Host(); host.host = tld; } CatalogueEntry seed = new CatalogueEntry(); seed.location = line; seed.initialDepth = 0; seed.status = Status.PENDING; seed.host = host; if (catalogueService.findForLocation(seed.location) == null) { LOGGER.info("Found seed: {}", line); catalogueService.save(seed); } } } }
From source file:data_gen.Data_gen.java
private static void switch_file(List<String> tx) throws IOException { if (listOfFiles.length == 1) { file_index = 0;/* ww w. j av a2 s . co m*/ LineIterator it = FileUtils.lineIterator(listOfFiles[file_index]); while (it.hasNext()) { tx.add(it.nextLine()); } } if (listOfFiles.length > 1) { ++file_index; LineIterator it = FileUtils.lineIterator(listOfFiles[file_index]); while (it.hasNext()) { tx.add(it.nextLine()); } if (file_index == listOfFiles.length - 1) { file_index = 0; } } }
From source file:com.edgenius.wiki.service.impl.BackupServiceImpl.java
/** * @param binderFile/* ww w .j a va 2 s. com*/ */ private int versionCheck(File binderFile) { //it does not worth to use any XML technique to get version number... String verStr = null; LineIterator iter = null; try { for (iter = FileUtils.lineIterator(binderFile); iter.hasNext();) { String line = iter.nextLine(); if (verStr != null) { int eIdx = line.indexOf("</version>"); if (eIdx != -1) { verStr += line.substring(0, eIdx); break; } else { AuditLogger.error("Version in binder can not find close tag in next line, failed~"); } //I don't bear version tag in more than 2 lines! break; } int sIdx = line.indexOf("<version>"); if (sIdx != -1) { int eIdx = line.indexOf("</version>"); if (eIdx != -1) { verStr = line.substring(sIdx + "<version>".length(), eIdx); break; } else { verStr = line.substring(sIdx + "<version>".length()); AuditLogger.error("Version in binder even not insdie same line!?"); } } } } catch (IOException e) { log.error("Unable to read binder file to get version ", e); } finally { if (iter != null) iter.close(); } if (verStr == null || NumberUtils.toFloat(verStr.trim(), -1f) == -1f) { log.error("version parse failed."); return 0; } //upgrade binder file try { upgradeService.doBackupPackageUpgardeForBinder(verStr.trim(), binderFile); } catch (Exception e) { log.error("Unexpected erorr while upgrade backup binder file from " + verStr.trim() + " to " + Version.VERSION, e); } return (int) (NumberUtils.toFloat(verStr.trim(), 0) * 1000); }
From source file:io.hops.hopsworks.common.util.HopsUtils.java
/** * Read blacklisted Spark properties from file * @return Blacklisted Spark properties//from w w w . j a v a2 s . c om * @throws IOException */ private static Set<String> readBlacklistedSparkProperties(String sparkDir) throws IOException { File sparkBlacklistFile = Paths.get(sparkDir, Settings.SPARK_BLACKLISTED_PROPS).toFile(); LineIterator lineIterator = FileUtils.lineIterator(sparkBlacklistFile); Set<String> blacklistedProps = new HashSet<>(); try { while (lineIterator.hasNext()) { String line = lineIterator.nextLine(); if (!line.startsWith("#")) { blacklistedProps.add(line); } } return blacklistedProps; } finally { LineIterator.closeQuietly(lineIterator); } }
From source file:nl.ru.cmbi.vase.tools.util.ToolBox.java
public static StringBuilder getStringBuilderFromFile(final String fileName) throws IOException { // int STRINGBUILDER_SIZE = 403228383; // big! File file = new File(fileName); LineIterator it = FileUtils.lineIterator(file); StringBuilder sb = new StringBuilder(); // STRINGBUILDER_SIZE while (it.hasNext()) { sb.append(it.nextLine());/*from w w w .j av a 2s. c o m*/ sb.append("\n"); } it.close(); return sb; }
From source file:org.adf.emg.sonar.ojaudit.JavaMetricsDecorator.java
@Override public void decorate(Resource resource, DecoratorContext context) { if (!(Qualifiers.isFile(resource) && resource.getName().endsWith(".java"))) { // only process .java files return;// www. ja v a 2 s.c o m } ProjectFileSystem fileSystem = context.getProject().getFileSystem(); File file = lookup(resource, fileSystem); LineIterator iterator = null; int numLines = 0; int numBlankLines = 0; int numCommentLines = 0; try { Charset charset = fileSystem.getSourceCharset(); iterator = charset == null ? FileUtils.lineIterator(file) : FileUtils.lineIterator(file, charset.name()); boolean inComment = false; while (iterator.hasNext()) { String trimmedLine = iterator.nextLine().trim(); numLines++; boolean lineHasCode = false; boolean lineHasComment = false; while (!trimmedLine.isEmpty()) { if (inComment) { // in a comment. try to find end marker int endIndex = trimmedLine.indexOf(END_COMMENT); if (endIndex == -1) { // (rest of) line is comment lineHasComment = true; trimmedLine = ""; // remove comment } else { // remove comment to see if there is code after it lineHasComment = true; trimmedLine = trimmedLine.substring(endIndex + END_COMMENT.length()); inComment = false; } } else { // not in a comment if (trimmedLine.startsWith("//")) { trimmedLine = ""; continue; } // try to find begin comment marker int startIndex = trimmedLine.indexOf(START_COMMENT); if (startIndex == -1) { // (rest of) line is non-comment lineHasCode = true; trimmedLine = ""; // remove non-comment } else if (startIndex == 0) { // line starts with start marker inComment = true; trimmedLine = trimmedLine.substring(startIndex + START_COMMENT.length()); } else { // line contains start marker lineHasCode = true; inComment = true; trimmedLine = trimmedLine.substring(startIndex + START_COMMENT.length()); } } trimmedLine = trimmedLine.trim(); } if (!lineHasCode) { if (lineHasComment) { numCommentLines++; } else { numBlankLines++; } } } } catch (IOException e) { LOG.warn("error reading " + file + " to collect metrics", e); } finally { LineIterator.closeQuietly(iterator); } context.saveMeasure(CoreMetrics.LINES, (double) numLines); // Lines context.saveMeasure(CoreMetrics.COMMENT_LINES, (double) numCommentLines); // Non Commenting Lines of Code context.saveMeasure(CoreMetrics.NCLOC, (double) numLines - numBlankLines - numCommentLines); // Comment Lines }