@Override
 public boolean hasNext() {
   try {
     return !buffer.isEmpty()
         || iterator.hasNext()
         || (currentReader != null && currentReader.ready());
   } catch (IOException e) {
     // this exception is possible only at currentReader.ready(), so it means that it's definitely
     // NOT ready
     return false;
   }
 }
  @Override
  public String nextSentence() {
    if (buffer.size() < linesToFetch) {
      // prefetch
      if (currentReader != null) {
        fetchLines(linesToFetch);
      } else if (this.iterator.hasNext()) {
        currentReader = new BufferedReader(new InputStreamReader(iterator.nextDocument()));
        fetchLines(linesToFetch);
      }
    }

    // actually its the same. You get string or you get null as result of poll, if buffer is empty
    // after prefetch try
    if (buffer.size() < 1) return null;
    else return buffer.poll();
  }
 @Override
 public void reset() {
   iterator.reset();
 }