Search in sources :

Example 1 with URLStreamHandlerProvider

use of java.net.spi.URLStreamHandlerProvider in project Bytecoder by mirkosertic.

the class UrlDeserializedState method providers.

private static Iterator<URLStreamHandlerProvider> providers() {
    return new Iterator<>() {

        ClassLoader cl = ClassLoader.getSystemClassLoader();

        ServiceLoader<URLStreamHandlerProvider> sl = ServiceLoader.load(URLStreamHandlerProvider.class, cl);

        Iterator<URLStreamHandlerProvider> i = sl.iterator();

        URLStreamHandlerProvider next = null;

        private boolean getNext() {
            while (next == null) {
                try {
                    if (!i.hasNext())
                        return false;
                    next = i.next();
                } catch (ServiceConfigurationError sce) {
                    if (sce.getCause() instanceof SecurityException) {
                        // Ignore security exceptions
                        continue;
                    }
                    throw sce;
                }
            }
            return true;
        }

        public boolean hasNext() {
            return getNext();
        }

        public URLStreamHandlerProvider next() {
            if (!getNext())
                throw new NoSuchElementException();
            URLStreamHandlerProvider n = next;
            next = null;
            return n;
        }
    };
}
Also used : ServiceLoader(java.util.ServiceLoader) URLStreamHandlerProvider(java.net.spi.URLStreamHandlerProvider) Iterator(java.util.Iterator) ServiceConfigurationError(java.util.ServiceConfigurationError) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

URLStreamHandlerProvider (java.net.spi.URLStreamHandlerProvider)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 ServiceLoader (java.util.ServiceLoader)1