List of usage examples for org.apache.commons.io FileUtils lineIterator
public static LineIterator lineIterator(File file, String encoding) throws IOException
File
. 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 ww w.ja v a 2 s. co 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()); } }
From source file:com.level3.hiper.dyconn.network.device.Repository.java
public synchronized void load(String fn) throws IOException { fileName = fn;//from w w w . j a v a 2s . c om // 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:com.polytech4A.cuttingstock.core.resolution.util.context.ContextLoaderUtils.java
/** * Load the content of the context file. * * @param path path of the context File. * @return Context loaded./*from w w w. ja va2s . c o m*/ * @throws IOException if file not found. * @throws MalformedContextFileException if the Context file don't have the right structure. * @throws IllogicalContextException if an image is bigger than pattern max size. */ public static Context loadContext(String path) throws IOException, MalformedContextFileException, IllogicalContextException { File file = new File(path); LineIterator it = FileUtils.lineIterator(file, "UTF-8"); ArrayList<Box> boxes = new ArrayList<>(); try { Double x = loadLine(it, "^LX=[0-9]{1,13}(\\.[0-9]*)?$"); Double y = loadLine(it, "LY=[0-9]{1,13}(\\.[0-9]*)?"); int cost = loadLine(it, "m=[0-9]{1,13}(\\.[0-9]*)?").intValue(); while (it.hasNext()) { boxes.add(loadBox(it.nextLine())); } LineIterator.closeQuietly(it); double max = Math.max(x, y); if (boxes.parallelStream().anyMatch(b -> b.getSize().getX() > max) || boxes.parallelStream().anyMatch(b -> b.getSize().getY() > max)) { throw new IllogicalContextException("There is an image which is bigger than the pattern."); } return new Context(file.getName(), 20, 1, boxes, new Vector(x, y)); } catch (MalformedContextFileException mctx) { throw mctx; } finally { LineIterator.closeQuietly(it); } }
From source file:fr.ericlab.util.Util.java
static public LinkedList<String> readStopWords(String pathToStopwordsFile) { LinkedList<String> stopWords = new LinkedList<>(); if (pathToStopwordsFile != null) { LineIterator it = null;//w ww. j av a2s . c o m try { it = FileUtils.lineIterator(new File(pathToStopwordsFile), "UTF-8"); while (it.hasNext()) { stopWords.add(it.nextLine()); } } catch (IOException ex) { Logger.getLogger(MABED.class.getName()).log(Level.SEVERE, null, ex); } finally { LineIterator.closeQuietly(it); } } return stopWords; }
From source file:net.mindengine.blogix.tests.RequestSampleParser.java
public static List<Pair<String, String>> loadRequestChecksFromFile(File file) throws IOException { List<Pair<String, String>> samples = new LinkedList<Pair<String, String>>(); LineIterator it = FileUtils.lineIterator(file, "UTF-8"); RequestSampleParser parser = new RequestSampleParser(samples, it); while (it.hasNext()) { parser = parser.process(it.nextLine()); }//from w w w . j av a 2s.c o m parser.done(); return samples; }
From source file:net.mindengine.blogix.db.DbEntryParser.java
public Map<String, String> load() throws IOException { LineIterator lineIterator = FileUtils.lineIterator(file, UTF_8); ParsingState state = new DummyState(); while (state != null && lineIterator.hasNext()) { state = state.readLine(lineIterator); if (!lineIterator.hasNext()) { if (state != null) { state.done();/* ww w .j a va 2 s .c om*/ } break; } } return data; }
From source file:net.ostis.scpdev.debug.core.model.M4SCPUtils.java
/** * Iterate over line in source file to line with lineNumber * and find program or procedure declaration with less or equal line number. * @return program name if success else null. */// w w w. j a va 2 s.c o m public static String getProgramNameFromLine(final IFile file, final int lineNumber) throws CoreException { try { LineIterator iter = FileUtils.lineIterator(file.getLocation().toFile(), file.getCharset()); String curProgram = null; int curLineNumber = 0; while (iter.hasNext() && curLineNumber < lineNumber) { ++curLineNumber; String line = iter.nextLine(); // Find start of declaration program or procedure in line. Matcher startMatcher = programStartDeclrPattern.matcher(line); if (startMatcher.matches()) curProgram = startMatcher.group(2); // Find end of declaration program or procedure in line. Matcher endMatcher = programEndDeclrPattern.matcher(line); if (endMatcher.matches()) curProgram = null; } return curProgram; } catch (IOException e) { throw new CoreException(StatusUtils.makeStatus(IStatus.ERROR, "Error find m4scp program name", e)); } }
From source file:com.google.demo.translate.Translator.java
private static void parseInputs() { Properties prop = new Properties(); try {//from w w w.j a va2 s . c o m prop.load(Translator.class.getClassLoader().getResourceAsStream("languages.properties")); it = FileUtils.lineIterator( new File(Translator.class.getClassLoader().getResource("input.csv").getPath()), "UTF-8"); } catch (IOException e) { throw new RuntimeException(e); } source = prop.getProperty("source"); String targetsList = prop.getProperty("targets"); targets = new ArrayList<>(Arrays.asList(targetsList.split(","))); String path = Translator.class.getClassLoader().getResource("").getPath() + "output.csv"; output = Paths.get(path); }
From source file:com.googlecode.jsonschema2pojo.integration.util.FileSearchMatcher.java
private boolean isSearchTextPresentInLinesOfFile(File f) { LineIterator it = null;//ww w. j a v a 2 s . com try { 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:net.orzo.lib.Files.java
/** * Obtains an iterator which reads provided file (specified by path) line by * line. Iterator can be accessed by a classic method pair <i>hasNext()</li> * and <i>next()</i>.//w ww . ja va 2s. co m */ public FileIterator<Object> fileReader(final String path, final String encoding) throws IOException { final LineIterator itr = FileUtils.lineIterator(new File(path), encoding); return new FileIterator<Object>() { @Override public boolean hasNext() { return itr.hasNext(); } @Override public Object next() { return itr.nextLine(); // TODO wrapping??? } @Override public void remove() { itr.remove(); } public void close() { itr.close(); } public String getPath() { if (File.separator.equals("/")) { return path; } else { return path.replace(File.separator, "/"); } } }; }