List of usage examples for org.apache.commons.io LineIterator closeQuietly
public static void closeQuietly(LineIterator iterator)
From source file:net.pms.io.OutputTextLogger.java
public void run() { LineIterator it = null;//from w w w . j a v a2 s . co m try { 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:net.pms.io.OutputTextConsumer.java
public void run() { LineIterator it = null;//from w w w.ja v a 2 s . c o m try { it = IOUtils.lineIterator(inputStream, "UTF-8"); while (it.hasNext()) { String line = it.nextLine(); if (line.length() > 0) { addLine(line); } if (log) { 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:com.googlecode.jsonschema2pojo.integration.util.FileSearchMatcher.java
private boolean isSearchTextPresentInLinesOfFile(File f) { LineIterator it = null;/*from ww w .j av a2 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:com.sindicetech.siren.demo.bnb.BNBDemo.java
public void index() throws IOException { final SimpleIndexer indexer = new SimpleIndexer(indexDir); try {/*from w w w . ja v a 2 s . c om*/ int counter = 0; final LineIterator it = FileUtils.lineIterator(BNB_PATH); while (it.hasNext()) { final String id = Integer.toString(counter++); final String content = (String) it.next(); logger.info("Indexing document {}", id); indexer.addDocument(id, content); } LineIterator.closeQuietly(it); logger.info("Committing all pending documents"); indexer.commit(); } finally { logger.info("Closing index"); indexer.close(); } }
From source file:mitm.common.postfix.PostfixMainConfigParser.java
private static List<String> normalize(Reader config) { List<String> lines = new LinkedList<String>(); LineIterator it = new LineIterator(config); String line = ""; try {/*from www .jav a 2s . c o m*/ while (it.hasNext()) { String nextLine = it.nextLine(); Matcher matcher = CONTINUATION.matcher(nextLine); if (!nextLine.trim().startsWith("#") && matcher.matches()) { /* its a continuation line */ line = line + LF + nextLine; } else { matcher = NAME_VALUE.matcher(nextLine); if (matcher.matches()) { /* its a name/value line */ if (StringUtils.isNotEmpty(line)) { /* store the previous line because it is finished */ lines.add(line); } line = nextLine; } else { /* it's some other line like a comment */ if (StringUtils.isNotEmpty(line)) { /* store the previous line because it is finished */ lines.add(line); } lines.add(nextLine); line = ""; } } } if (StringUtils.isNotEmpty(line)) { lines.add(line); } } finally { LineIterator.closeQuietly(it); } return lines; }
From source file:com.comcast.cats.monitor.util.FileSearchUtil.java
public static List<String> getLinesByRegex(String filePath, String expression) throws IOException { if ((null == expression) || (expression.isEmpty()) || (null == filePath) || (filePath.isEmpty())) { throw new IllegalArgumentException("Expressions/FilePath is NULL of EMPTY !!!"); }/*w w w. j ava 2s . c o m*/ File file = new File(filePath); Pattern pattern = Pattern.compile(expression); List<String> lines = new LinkedList<String>(); if (file.exists()) { LineIterator lineIterator = FileUtils.lineIterator(file, UTF_8_ENCODING); try { while (lineIterator.hasNext()) { String line = lineIterator.nextLine(); if (pattern.matcher(line).find()) { lines.add(line); } } } finally { LineIterator.closeQuietly(lineIterator); } } return lines; }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.evaluation.phrasematch.LineReader.java
@Override public List<String> getListOfStrings(JCas jcas) throws AnalysisEngineProcessException { List<String> goldList = new ArrayList<String>(); LineIterator lineIterator;//from ww w .j ava2 s . c o m try { lineIterator = FileUtils.lineIterator(new File(getPath(getDocumentBaseName(jcas))), encoding); } catch (IOException e) { throw new AnalysisEngineProcessException(new Throwable(e)); } try { while (lineIterator.hasNext()) { String line = lineIterator.nextLine().trim(); if (!line.isEmpty()) { if (lowercase) line = line.toLowerCase(); goldList.add(line); } } } finally { LineIterator.closeQuietly(lineIterator); } return goldList; }
From source file:com.kolich.common.util.io.JumpToLine.java
/** * Closes this IOUtils LineIterator and the underlying * input stream reader. */ public void close() { IOUtils.closeQuietly(is_); LineIterator.closeQuietly(it_); }
From source file:com.ipcglobal.fredimport.process.Reference.java
/** * Creates the ref sexes./*from www . j a va 2 s .c o m*/ * * @param path the path * @throws Exception the exception */ private void createRefSexes(String path) throws Exception { refSexes = new HashMap<String, String>(); LineIterator it = FileUtils.lineIterator(new File(path + FILENAME_SEXES), "UTF-8"); try { while (it.hasNext()) { // Format: <identifier>|<M|F|A> // Example: All Persons|A String line = it.nextLine(); String[] fields = line.split("[|]"); refSexes.put(fields[0].trim(), fields[1].trim()); } } finally { LineIterator.closeQuietly(it); } }
From source file:com.norconex.collector.fs.crawler.FilesystemCrawler.java
private void queueStartPaths(ICrawlDataStore crawlDataStore) { // Queue regular start urls String[] startPaths = getCrawlerConfig().getStartPaths(); if (startPaths != null) { for (int i = 0; i < startPaths.length; i++) { String startPath = startPaths[i]; executeQueuePipeline(new BaseCrawlData(startPath), crawlDataStore); }/*from ww w .ja v a 2s.c om*/ } // Queue start urls define in one or more seed files String[] pathsFiles = getCrawlerConfig().getPathsFiles(); if (pathsFiles != null) { for (int i = 0; i < pathsFiles.length; i++) { String pathsFile = pathsFiles[i]; LineIterator it = null; try { it = IOUtils.lineIterator(new FileInputStream(pathsFile), CharEncoding.UTF_8); while (it.hasNext()) { String startPath = it.nextLine(); executeQueuePipeline(new BaseCrawlData(startPath), crawlDataStore); } } catch (IOException e) { throw new CollectorException("Could not process paths file: " + pathsFile, e); } finally { LineIterator.closeQuietly(it); ; } } } }