@Override public boolean hasNext() { return lineIterator.hasNext(); }
/** * Returns the next line in the wrapped <code>Reader</code>. * * @return the next line from the input * @throws NoSuchElementException if there is no line to return */ public String nextLine() { if (!hasNext()) { throw new NoSuchElementException("No more lines"); } final String currentLine = cachedLine; cachedLine = null; return currentLine; }
/** * Returns the next line in the wrapped <code>Reader</code>. * * @return the next line from the input * @throws NoSuchElementException if there is no line to return */ public String nextLine() { if (!hasNext()) { throw new NoSuchElementException("No more lines"); } String currentLine = cachedLine; cachedLine = null; return currentLine; }
LineIterator it = IOUtils.lineIterator( new BufferedReader(new FileReader("file.txt"))); for (int lineNumber = 0; it.hasNext(); lineNumber++) { String line = (String) it.next(); if (lineNumber == expectedLineNumber) { return line; } }
protected Map<String, String> getMigrateMap() throws IOException { Map<String,String> map = new HashMap<String,String>(); InputStream inStream = getClass().getResourceAsStream( "/org/archive/crawler/migrate/H1toH3.map"); LineIterator iter = IOUtils.lineIterator(inStream, "UTF-8"); while(iter.hasNext()) { String[] fields = iter.nextLine().split("\\|"); map.put(fields[1], fields[0]); } inStream.close(); return map; }
LineIterator it = FileUtils.lineIterator(file, "UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); // do something with line } } finally { it.close(); }
public void run() { try (LineIterator lineIterator = IOUtils.lineIterator(in)) { while (lineIterator.hasNext()) { consumeLine(lineIterator.nextLine()); } } catch (Exception ignore) { } finally { completed = true; } }
@Test public void testNextWithException() throws Exception { final Reader reader = new BufferedReader(new StringReader("")) { @Override public String readLine() throws IOException { throw new IOException("hasNext"); } }; try { new LineIterator(reader).hasNext(); fail("Expected IllegalStateException"); } catch (final IllegalStateException e) { // expected } }
private void assertLines(final List<String> lines, final LineIterator iterator) { try { for (int i = 0; i < lines.size(); i++) { final String line = iterator.nextLine(); assertEquals("nextLine() line " + i, lines.get(i), line); } assertFalse("No more expected", iterator.hasNext()); } finally { LineIterator.closeQuietly(iterator); } }
LineIterator it = FileUtils.lineIterator(jsonFile); try { while (it.hasNext()) { String line = it.nextLine(); lineNum++;
int[] theShape = null; double[] subsetArr = null; while (it.hasNext()) { String line = it.nextLine(); lineNum++;
/** * Uncomment properties. * * @param url Source to uncomment client properties for. * @return Temporary file with uncommented client properties. * @throws IOException In case of IO exception. */ private File uncommentProperties(URL url) throws IOException { InputStream in = url.openStream(); assertNotNull(in); LineIterator it = IOUtils.lineIterator(in, "UTF-8"); Collection<String> lines = new ArrayList<>(); while (it.hasNext()) lines.add(it.nextLine().replace("#ignite.client.", "ignite.client.")); IgniteUtils.closeQuiet(in); File tmp = File.createTempFile(UUID.randomUUID().toString(), "properties"); tmp.deleteOnExit(); FileUtils.writeLines(tmp, lines); return tmp; }
@Test public void testNextOnly() throws Exception { final String encoding = null; final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt"); final List<String> lines = createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try { for (int i = 0; i < lines.size(); i++) { final String line = iterator.next(); assertEquals("next() line " + i, lines.get(i), line); } assertEquals("No more expected", false, iterator.hasNext()); } finally { LineIterator.closeQuietly(iterator); } }
@Test public void testValidEncoding() throws Exception { final String encoding = "UTF-8"; final File testFile = new File(getTestDirectory(), "LineIterator-validEncoding.txt"); createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try { int count = 0; while (iterator.hasNext()) { assertNotNull(iterator.next()); count++; } assertEquals(3, count); } finally { LineIterator.closeQuietly(iterator); } }
while (iterator.hasNext()) { final String line = iterator.next(); assertEquals("Comparing line " + idx, lines.get(idx), line);
while (iterator.hasNext()) { final String line = iterator.next(); actualLines++;
while (it.hasNext()){ String line = it.nextLine(); if(line.matches("myRegEx")){
while (lineIt.hasNext()) { String[] d = lineIt.next().split(";"); String fileName = d[0];