@Test public void test() throws Exception { File f = new File(getClass().getResource("lineReader.txt").getPath()); BaleenCollectionReader bcr = getCollectionReader(LineReader.PARAM_FILE, f.getPath()); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("This is the first line", jCas.getDocumentText()); assertEquals(2, JCasUtil.select(jCas, Metadata.class).size()); Metadata md = JCasUtil.selectByIndex(jCas, Metadata.class, 1); assertEquals("lineNumber", md.getKey()); assertEquals("1", md.getValue()); assertTrue(getSource(jCas).endsWith("#1")); jCas.reset(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("This is the second line", jCas.getDocumentText()); assertEquals(2, JCasUtil.select(jCas, Metadata.class).size()); md = JCasUtil.selectByIndex(jCas, Metadata.class, 1); assertEquals("lineNumber", md.getKey()); assertEquals("2", md.getValue()); assertTrue(getSource(jCas).endsWith("#2")); jCas.reset(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("This is the fourth line, but the third one we pick out", jCas.getDocumentText()); md = JCasUtil.selectByIndex(jCas, Metadata.class, 1); assertEquals("lineNumber", md.getKey()); assertEquals("4", md.getValue()); assertTrue(getSource(jCas).endsWith("#4")); jCas.reset(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals( "This is the sixth line, but the fourth and final one we pick out", jCas.getDocumentText()); md = JCasUtil.selectByIndex(jCas, Metadata.class, 1); assertEquals("lineNumber", md.getKey()); assertEquals("6", md.getValue()); assertTrue(getSource(jCas).endsWith("#6")); jCas.reset(); assertFalse(bcr.doHasNext()); assertFalse(bcr.doHasNext()); bcr.close(); }
@Override public boolean doHasNext() throws IOException, CollectionException { if (br == null) { return false; } while ((line = br.readLine()) != null) { lineNumber++; line = line.trim(); if (!line.isEmpty()) { return true; } } try { br.close(); } catch (IOException ioe) { getMonitor().debug("An error occurred when closing the BufferedReader", ioe); } br = null; return false; }
LineReader extends BaleenCollectionReader { @Override public boolean doHasNext() throws IOException, CollectionException { if (br == null) { return false; } while ((line = br.readLine()) != null) { lineNumber++; line = line.trim(); if (!line.isEmpty()) { return true; } } try { br.close(); } catch (IOException ioe) { getMonitor().debug("An error occurred when closing the BufferedReader", ioe); } br = null; return false; } }
LineReader extends BaleenCollectionReader { @Override public boolean doHasNext() throws IOException, CollectionException { if (br == null) { return false; } while ((line = br.readLine()) != null) { lineNumber++; line = line.trim(); if (!line.isEmpty()) { return true; } } try { br.close(); } catch (IOException ioe) { getMonitor().debug("An error occurred when closing the BufferedReader", ioe); } br = null; return false; }  }
LineReader extends BaleenCollectionReader { @Override public boolean doHasNext() throws IOException, CollectionException { if (br == null) { return false; } while ((line = br.readLine()) != null) { lineNumber++; line = line.trim(); if (!line.isEmpty()) { return true; } } try { br.close(); } catch (IOException ioe) { getMonitor().debug("An error occurred when closing the BufferedReader", ioe); } br = null; return false; }  @Override boolean doHasNext(); }
LineReader extends BaleenCollectionReader { @Override public boolean doHasNext() throws IOException, CollectionException { if (br == null) { return false; } while ((line = br.readLine()) != null) { lineNumber++; line = line.trim(); if (!line.isEmpty()) { return true; } } try { br.close(); } catch (IOException ioe) { getMonitor().debug("An error occurred when closing the BufferedReader", ioe); } br = null; return false; }  @Override boolean doHasNext(); static final String PARAM_FILE; }