Esempio n. 1
0
        /// <summary>
        /// Closes this URLClassLoader, so that it can no longer be used to load
        /// new classes or resources that are defined by this loader.
        /// Classes and resources defined by any of this loader's parents in the
        /// delegation hierarchy are still accessible. Also, any classes or resources
        /// that are already loaded, are still accessible.
        /// <para>
        /// In the case of jar: and file: URLs, it also closes any files
        /// that were opened by it. If another thread is loading a
        /// class when the {@code close} method is invoked, then the result of
        /// that load is undefined.
        /// </para>
        /// <para>
        /// The method makes a best effort attempt to close all opened files,
        /// by catching <seealso cref="IOException"/>s internally. Unchecked exceptions
        /// and errors are not caught. Calling close on an already closed
        /// loader has no effect.
        /// </para>
        /// <para>
        /// </para>
        /// </summary>
        /// <exception cref="IOException"> if closing any file opened by this class loader
        /// resulted in an IOException. Any such exceptions are caught internally.
        /// If only one is caught, then it is re-thrown. If more than one exception
        /// is caught, then the second and following exceptions are added
        /// as suppressed exceptions of the first one caught, which is then re-thrown.
        /// </exception>
        /// <exception cref="SecurityException"> if a security manager is set, and it denies
        ///   <seealso cref="RuntimePermission"/>{@code ("closeClassLoader")}
        ///
        /// @since 1.7 </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void close() throws java.io.IOException
        public virtual void Close()
        {
            SecurityManager security = System.SecurityManager;

            if (security != null)
            {
                security.CheckPermission(new RuntimePermission("closeClassLoader"));
            }
            IList <IOException> errors = Ucp.closeLoaders();

            // now close any remaining streams.

            lock (Closeables)
            {
                WeakHashMap <Closeable, Void> .KeyCollection keys = Closeables.KeySet();
                foreach (Closeable c in keys)
                {
                    try
                    {
                        c.Close();
                    }
                    catch (IOException ioex)
                    {
                        errors.Add(ioex);
                    }
                }
                Closeables.Clear();
            }

            if (errors.Count == 0)
            {
                return;
            }

            IOException firstex = errors.Remove(0);

            // Suppress any remaining exceptions

            foreach (IOException error in errors)
            {
                firstex.AddSuppressed(error);
            }
            throw firstex;
        }
Esempio n. 2
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);
        }