@Test public void testNextDocument() throws Exception { ClassPathResource reuters5250 = new ClassPathResource("/reuters/5250"); File f = reuters5250.getFile(); DocumentIterator iter = new FileDocumentIterator(f.getAbsolutePath()); log.info(f.getAbsolutePath()); int cnt = 0; while (iter.hasNext()) { InputStream stream = iter.nextDocument(); stream.close(); cnt++; } assertEquals(24, cnt); }
@Override public synchronized InputStream nextDocument() { try { if (lineIterator != null && !lineIterator.hasNext() && iter.hasNext()) { File next = iter.next(); lineIterator.close(); lineIterator = FileUtils.lineIterator(next); while (!lineIterator.hasNext()) { lineIterator.close(); lineIterator = FileUtils.lineIterator(next); } } if (lineIterator != null && lineIterator.hasNext()) { return new BufferedInputStream(IOUtils.toInputStream(lineIterator.nextLine())); } } catch (Exception e) { log.warn("Error reading input stream...this is just a warning..Going to return", e); return null; } return null; }
FileDocumentIterator implements DocumentIterator { @Override public synchronized InputStream nextDocument() { try { if (lineIterator != null && !lineIterator.hasNext() && iter.hasNext()) { File next = iter.next(); lineIterator.close(); lineIterator = FileUtils.lineIterator(next); while (!lineIterator.hasNext()) { lineIterator.close(); lineIterator = FileUtils.lineIterator(next); } } if (lineIterator != null && lineIterator.hasNext()) { return new BufferedInputStream(IOUtils.toInputStream(lineIterator.nextLine())); } } catch (Exception e) { log.warn("Error reading input stream...this is just a warning..Going to return", e); return null; } return null; } }
FileDocumentIterator implements DocumentIterator { @Override public synchronized InputStream nextDocument() { try { if (lineIterator != null && !lineIterator.hasNext() && iter.hasNext()) { File next = iter.next(); lineIterator.close(); lineIterator = FileUtils.lineIterator(next); while (!lineIterator.hasNext()) { lineIterator.close(); lineIterator = FileUtils.lineIterator(next); } } if (lineIterator != null && lineIterator.hasNext()) { return new BufferedInputStream(IOUtils.toInputStream(lineIterator.nextLine())); } } catch (Exception e) { log.warn("Error reading input stream...this is just a warning..Going to return", e); return null; } return null; } FileDocumentIterator(String path);  FileDocumentIterator(File path); }
FileDocumentIterator implements DocumentIterator { @Override public synchronized InputStream nextDocument() { try { if (lineIterator != null && !lineIterator.hasNext() && iter.hasNext()) { File next = iter.next(); lineIterator.close(); lineIterator = FileUtils.lineIterator(next); while (!lineIterator.hasNext()) { lineIterator.close(); lineIterator = FileUtils.lineIterator(next); } } if (lineIterator != null && lineIterator.hasNext()) { return new BufferedInputStream(IOUtils.toInputStream(lineIterator.nextLine())); } } catch (Exception e) { log.warn("Error reading input stream...this is just a warning..Going to return", e); return null; } return null; } FileDocumentIterator(String path);  FileDocumentIterator(File path); @Override synchronized InputStream nextDocument(); @Override synchronized boolean hasNext(); @Override void reset(); }
FileDocumentIterator implements DocumentIterator { @Override public synchronized InputStream nextDocument() { try { if (lineIterator != null && !lineIterator.hasNext() && iter.hasNext()) { File next = iter.next(); lineIterator.close(); lineIterator = FileUtils.lineIterator(next); while (!lineIterator.hasNext()) { lineIterator.close(); lineIterator = FileUtils.lineIterator(next); } } if (lineIterator != null && lineIterator.hasNext()) { return new BufferedInputStream(IOUtils.toInputStream(lineIterator.nextLine())); } } catch (Exception e) { log.warn("Error reading input stream...this is just a warning..Going to return", e); return null; } return null; } FileDocumentIterator(String path);  FileDocumentIterator(File path); @Override synchronized InputStream nextDocument(); @Override synchronized boolean hasNext(); @Override void reset();  }