CsvFolderReader extends BaleenCollectionReader { @Override public boolean doHasNext() throws IOException, CollectionException { WatchKey key; while ((key = watcher.poll()) != null) { for (WatchEvent<?> event : key.pollEvents()) { processEvent(key, event); getMonitor().meter("events").mark(); } key.reset(); } return !currLines.isEmpty() || !queue.isEmpty(); }  @Override void doInitialize(UimaContext context); @Override void doGetNext(JCas jCas); @Override void doClose(); @Override boolean doHasNext(); static final String PARAM_FOLDERS; static final String PARAM_REPROCESS_ON_MODIFY; static final String PARAM_RECURSIVE; static final String PARAM_SEPARATOR; static final String PARAM_EXTENSION; static final String PARAM_TEXT_COLUMNS; }
@Test public void test() throws Exception { List<String> lines1 = new ArrayList<>(); lines1.add("id,date,content,evaluated"); lines1.add("1,2017-10-11 14:58:00,\"Hello, world!\",Y"); lines1.add("2,2017-10-11 14:58:18,\"Hello, Ben!\",N"); Path p1 = new File(inputDir, TEST1_FILE).toPath(); Files.write(p1, lines1); BaleenCollectionReader bcr = getCollectionReader(CsvFolderReader.PARAM_FOLDERS, new String[] {inputDir.getPath()}); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("Hello, world!", jCas.getDocumentText()); Map<String, String> meta1 = new HashMap<>(); JCasUtil.select(jCas, Metadata.class).forEach(md -> meta1.put(md.getKey(), md.getValue())); assertEquals(3, meta1.size()); assertEquals("1", meta1.get("id")); assertEquals("2017-10-11 14:58:00", meta1.get("date")); assertEquals("Y", meta1.get("evaluated")); assertEquals(p1.toRealPath().toString() + "#1", getSource(jCas)); jCas.reset(); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("Hello, Ben!", jCas.getDocumentText()); Map<String, String> meta2 = new HashMap<>(); JCasUtil.select(jCas, Metadata.class).forEach(md -> meta2.put(md.getKey(), md.getValue())); assertEquals(3, meta2.size()); assertEquals("2", meta2.get("id")); assertEquals("2017-10-11 14:58:18", meta2.get("date")); assertEquals("N", meta2.get("evaluated")); assertEquals(p1.toRealPath().toString() + "#2", getSource(jCas)); jCas.reset(); assertFalse(bcr.doHasNext()); List<String> lines2 = new ArrayList<>(); lines2.add("id,date,content,validated"); lines2.add("1,2017-10-12 15:13:23,\"Goodbye, Bob!\",N"); Path p2 = new File(inputDir, TEST2_FILE).toPath(); Files.write(p2, lines2); Thread.sleep(TIMEOUT); assertTrue(bcr.doHasNext()); bcr.getNext(jCas.getCas()); assertEquals("Goodbye, Bob!", jCas.getDocumentText()); Map<String, String> meta3 = new HashMap<>(); JCasUtil.select(jCas, Metadata.class).forEach(md -> meta3.put(md.getKey(), md.getValue())); assertEquals(3, meta3.size()); assertEquals("1", meta3.get("id")); assertEquals("2017-10-12 15:13:23", meta3.get("date")); assertEquals("N", meta3.get("validated")); assertEquals(p2.toRealPath().toString() + "#1", getSource(jCas)); jCas.reset(); assertFalse(bcr.doHasNext()); bcr.close(); }