private void fetchNextIfNeeded() { if (next == null) { FileTreeWalker.Event ev = walker.next(); while (ev != null) { IOException ioe = ev.ioeException(); if (ioe != null) throw new UncheckedIOException(ioe); // END_DIRECTORY events are ignored if (ev.type() != FileTreeWalker.EventType.END_DIRECTORY) { next = ev; return; } ev = walker.next(); } } }
@Override public Event next() { if (!walker.isOpen()) throw new IllegalStateException(); fetchNextIfNeeded(); if (next == null) throw new NoSuchElementException(); Event result = next; next = null; return result; }