code: public String nextLine() {
          if (hasNextPattern == linePattern())
              return getCachedResult();
          clearCaches();
  
          String result = findWithinHorizon(linePattern, 0);
          if (result == null)
              throw new NoSuchElementException("No line found");
          MatchResult mr = this.match();
          String lineSep = mr.group(1);
          if (lineSep != null)
              result = result.substring(0, result.length() - lineSep.length());
          if (result == null)
              throw new NoSuchElementException();
          else
              return result;
      }
docs: Advances this scanner past the current line and returns the input
  that was skipped.
  
  This method returns the rest of the current line, excluding any line
  separator at the end. The position is set to the beginning of the next
  line.
  
  <p>Since this method continues to search through the input looking
  for a line separator, it may buffer all of the input searching for
  the line to skip if no line separators are present.
  
  @return the line that was skipped
  @throws NoSuchElementException if no line was found
  @throws IllegalStateException if this scanner is closed