Beispiel #1
0
        /// <summary>
        /// Returns the next Event or {@code null} if there are no more events or
        /// the walker is closed.
        /// </summary>
        internal virtual Event Next()
        {
            DirectoryNode top = Stack.Peek();

            if (top == null)
            {
                return(null);                // stack is empty, we are done
            }

            // continue iteration of the directory at the top of the stack
            Event ev;

            do
            {
                Path        entry = null;
                IOException ioe   = null;

                // get next entry in the directory
                if (!top.Skipped())
                {
                    IEnumerator <Path> iterator = top.Iterator();
                    try
                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        if (iterator.hasNext())
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            entry = iterator.next();
                        }
                    }
                    catch (DirectoryIteratorException x)
                    {
                        ioe = x.InnerException;
                    }
                }

                // no next entry so close and pop directory, creating corresponding event
                if (entry == null)
                {
                    try
                    {
                        top.Stream().Close();
                    }
                    catch (IOException e)
                    {
                        if (ioe != null)
                        {
                            ioe = e;
                        }
                        else
                        {
                            ioe.AddSuppressed(e);
                        }
                    }
                    Stack.Pop();
                    return(new Event(EventType.END_DIRECTORY, top.Directory(), ioe));
                }

                // visit the entry
                ev = Visit(entry, true, true);                 // canUseCached -  ignoreSecurityException
            } while (ev == null);

            return(ev);
        }