Search in sources :

Example 1 with ResourceFinderException

use of org.glassfish.jersey.server.internal.scanning.ResourceFinderException in project jersey by jersey.

the class WebAppResourcesScanner method processPaths.

private void processPaths(final String... paths) {
    for (final String path : paths) {
        final Set<String> resourcePaths = sc.getResourcePaths(path);
        if (resourcePaths == null) {
            break;
        }
        compositeResourceFinder.push(new AbstractResourceFinderAdapter() {

            private final Deque<String> resourcePathsStack = new LinkedList<String>() {

                private static final long serialVersionUID = 3109256773218160485L;

                {
                    for (final String resourcePath : resourcePaths) {
                        push(resourcePath);
                    }
                }
            };

            private String current;

            private String next;

            @Override
            public boolean hasNext() {
                while (next == null && !resourcePathsStack.isEmpty()) {
                    next = resourcePathsStack.pop();
                    if (next.endsWith("/")) {
                        processPaths(next);
                        next = null;
                    } else if (next.endsWith(".jar")) {
                        try {
                            compositeResourceFinder.push(new JarFileScanner(sc.getResourceAsStream(next), "", true));
                        } catch (final IOException ioe) {
                            throw new ResourceFinderException(ioe);
                        }
                        next = null;
                    }
                }
                return next != null;
            }

            @Override
            public String next() {
                if (next != null || hasNext()) {
                    current = next;
                    next = null;
                    return current;
                }
                throw new NoSuchElementException();
            }

            @Override
            public InputStream open() {
                return sc.getResourceAsStream(current);
            }

            @Override
            public void reset() {
                throw new UnsupportedOperationException();
            }
        });
    }
}
Also used : InputStream(java.io.InputStream) ResourceFinderException(org.glassfish.jersey.server.internal.scanning.ResourceFinderException) IOException(java.io.IOException) JarFileScanner(org.glassfish.jersey.server.internal.scanning.JarFileScanner) AbstractResourceFinderAdapter(org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1 AbstractResourceFinderAdapter (org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter)1 JarFileScanner (org.glassfish.jersey.server.internal.scanning.JarFileScanner)1 ResourceFinderException (org.glassfish.jersey.server.internal.scanning.ResourceFinderException)1