List of usage examples for org.apache.commons.io LineIterator nextLine
public String nextLine()
Reader
. From source file:modelinspector.collectors.RequireAllCollector.java
public RequireAllCollector(String aName, String aLanguage, File aFile, String aEncoding, boolean aCaseSensitive) { name = aName;/*w w w. ja v a 2s. com*/ required = new HashSet<>(); language = new Locale(aLanguage); caseSensitive = aCaseSensitive; try (InputStream is = new FileInputStream(aFile)) { LineIterator i = IOUtils.lineIterator(is, aEncoding); while (i.hasNext()) { String[] fields = i.nextLine().split("\t"); String word = caseSensitive ? fields[0] : fields[0].toLowerCase(); required.add(word); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:avantssar.aslanpp.testing.DiskSpecificationsProvider.java
private boolean isSpec(File f) { boolean isSpecification = false; try {//from w ww.j av a2s . c o m LineIterator li = FileUtils.lineIterator(f); while (li.hasNext()) { String line = li.nextLine(); if (line.trim().length() > 0) { if (line.trim().startsWith("%")) { continue; } else { if (line.trim().startsWith("specification")) { isSpecification = true; } break; } } } } catch (IOException e) { Debug.logger.error("Failed to decide if specification or not: " + f.getAbsolutePath(), e); } return isSpecification; }
From source file:modelinspector.collectors.WordlistMatchCollector.java
public WordlistMatchCollector(String aName, String aLanguage, boolean aCaseSensitive, int aCutoff, String aFile, String aEncoding) {/*from w w w .java 2s . c o m*/ name = aName; baseVocabulary = new HashSet<>(); caseSensitive = aCaseSensitive; language = new Locale(aLanguage); cutoff = aCutoff; try (InputStream is = new FileInputStream(aFile)) { LineIterator i = IOUtils.lineIterator(is, aEncoding); while (i.hasNext()) { String[] fields = i.nextLine().split("\t"); if (fields.length > 1 && aCutoff > 0) { if (Integer.valueOf(fields[1]) < aCutoff) { continue; } } String word = aCaseSensitive ? fields[0] : fields[0].toLowerCase(language); baseVocabulary.add(word); } } catch (IOException e) { throw new RuntimeException(e); } originalBaseVocabularySize = baseVocabulary.size(); }
From source file:com.level3.hiper.dyconn.network.device.Repository.java
public synchronized void load(String fn) throws IOException { fileName = fn;// w ww .j a v a 2 s. c o m // entry from devices.txt // OVTR IRNG4838I7001 10.248.253.155 2c 161 0v3rtur31sg LineIterator it = FileUtils.lineIterator(new File(fn), "UTF-8"); deviceInfoMap.clear(); try { while (it.hasNext()) { String line = it.nextLine(); if ("".equals(line)) continue; if (line.startsWith("#")) continue; String[] parts = line.split("\\s+"); String name = parts[1]; deviceInfoMap.put(name, new Info(parts[0], parts[1], parts[2], parts[3], parts[4])); } } finally { it.close(); } }
From source file:convert.ConvertStrata.java
@Test public void convert() throws IOException { System.out.println("Convert strata test"); LineIterator it = FileUtils.lineIterator( new File("\\\\delphi\\felles\\alle\\smund\\stox\\strata_norskehavstoktet\\stratum1-6 2014.txt")); it.nextLine(); // skip header List<Coordinate> coords = new ArrayList<>(); String strata = null;/* www. j ava 2s . com*/ while (it.hasNext()) { String line = it.nextLine().trim(); String elms[] = line.split("\t"); String s = elms[2]; if (strata != null && !s.equals(strata)) { MultiPolygon mp = JTSUtils.createMultiPolygon(Arrays.asList(JTSUtils.createLineString(coords))); System.out.println(strata + "\t" + mp); coords.clear(); } coords.add(new Coordinate(Conversion.safeStringtoDoubleNULL(elms[1]), Conversion.safeStringtoDoubleNULL(elms[0]))); strata = s; } MultiPolygon mp = JTSUtils.createMultiPolygon(Arrays.asList(JTSUtils.createLineString(coords))); System.out.println(strata + "\t" + mp); }
From source file:net.pms.io.OutputTextLogger.java
public void run() { LineIterator it = null; try {//w w w.j a v a 2 s . c o m it = IOUtils.lineIterator(inputStream, "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); logger.debug(line); } } catch (IOException ioe) { logger.debug("Error consuming input stream: {}", ioe.getMessage()); } catch (IllegalStateException ise) { logger.debug("Error reading from closed input stream: {}", ise.getMessage()); } finally { LineIterator.closeQuietly(it); // clean up all associated resources } }
From source file:eu.eexcess.domaindetection.wordnet.WordnetDomainsReader.java
public void read(File file) throws IOException { System.out.println("Read in the original WordNet Domains file: " + file); LineIterator iterator = new LineIterator(new FileReader(file)); while (iterator.hasNext()) { String line = iterator.nextLine(); String[] tokens = line.split("[\t\\ ]"); String synset = tokens[0]; for (int i = 1; i < tokens.length; i++) { DomainAssignment assignment = new DomainAssignment(tokens[i], 1); Set<DomainAssignment> domains = synsetToDomains.get(synset); if (domains == null) { domains = new TreeSet<DomainAssignment>(); synsetToDomains.put(synset, domains); }/*from ww w. j a v a2 s. c o m*/ domains.add(assignment); } } iterator.close(); }
From source file:com.googlecode.jsonschema2pojo.integration.util.FileSearchMatcher.java
private boolean isSearchTextPresentInLinesOfFile(File f) { LineIterator it = null; try {/*from w w w.java 2s . c o m*/ it = FileUtils.lineIterator(f, "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); if (line.contains(searchText)) { return true; } } return false; } catch (IOException e) { throw new RuntimeException(e); } finally { LineIterator.closeQuietly(it); } }
From source file:eu.eexcess.domaindetection.wordnet.XwndReader.java
public void read(File file) throws IOException { String domain = FilenameUtils.getBaseName(file.getName()); File cacheFile = new File(file.getPath() + ".cache"); if (!cacheFile.exists()) { BinaryOutputStream bos = new BinaryOutputStream(new FileOutputStream(cacheFile)); System.out.println("Read in the Extended WordNet Domains file: " + file); LineIterator iterator = new LineIterator(new FileReader(file)); while (iterator.hasNext()) { String line = iterator.nextLine(); String[] tokens = line.split("\t"); String synset = tokens[0]; double weight = Double.parseDouble(tokens[1]); String[] ssid = synset.split("-"); int nr = Integer.parseInt(ssid[0]); POS pos = POS.getPOSForKey(ssid[1]); bos.writeInt(nr);/*from w w w. java2s.c o m*/ bos.writeSmallInt(pos.getId()); bos.writeInt(Float.floatToIntBits((float) weight)); } iterator.close(); bos.close(); } System.out.println("Read in the Extended WordNet Domains cache file: " + file); FileInputStream fStream = new FileInputStream(cacheFile); BinaryInputStream bis = new BinaryInputStream(fStream); while (bis.available() > 0) { int nr = bis.readInt(); int key = bis.readSmallInt(); POS pos = POS.getPOSForId(key); String synset = String.format("%08d-%s", nr, pos.getKey()); double weight = Float.intBitsToFloat(bis.readInt()); DomainAssignment assignment = new DomainAssignment(domain, weight); Set<DomainAssignment> domains = synsetToDomains.get(synset); if (domains == null) { domains = new TreeSet<DomainAssignment>(); synsetToDomains.put(synset, domains); } domains.add(assignment); } fStream.close(); bis.close(); }
From source file:cs.rsa.ts14.standard.TimesagEngine.java
public String getTimesagReport(File file, TimesagLineProcessor tlp) throws IOException { // Create an iterator for the lines in the file LineIterator it = FileUtils.lineIterator(file, "UTF-8"); tlp.beginProcess();/*from w ww . jav a2s .c o m*/ try { while (it.hasNext()) { // process each line String line = it.nextLine(); LineType linetype = tlp.process(line); if (linetype == LineType.INVALID_LINE) { // todo throw exception ? break; } } } finally { LineIterator.closeQuietly(it); } tlp.endProcess(); if (!tlp.lastError().equals("No error")) { return ("Error in input: " + tlp.lastError()); } else { return (tlp.getReport()); } }