use of org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter in project jersey by jersey.
the class FilesScanner method processFile.
private void processFile(final File f) {
if (f.getName().endsWith(".jar") || f.getName().endsWith(".zip")) {
try {
compositeResourceFinder.push(new JarFileScanner(new FileInputStream(f), "", true));
} catch (final IOException e) {
// logging might be sufficient in this case
throw new ResourceFinderException(e);
}
} else {
compositeResourceFinder.push(new AbstractResourceFinderAdapter() {
Stack<File> files = new Stack<File>() {
{
if (f.isDirectory()) {
final File[] subDirFiles = f.listFiles();
if (subDirFiles != null) {
for (final File file : subDirFiles) {
push(file);
}
}
} else {
push(f);
}
}
};
private File current;
private File next;
@Override
public boolean hasNext() {
while (next == null && !files.empty()) {
next = files.pop();
if (next.isDirectory()) {
if (recursive) {
processFile(next);
}
next = null;
} else if (next.getName().endsWith(".jar") || next.getName().endsWith(".zip")) {
processFile(next);
next = null;
}
}
return next != null;
}
@Override
public String next() {
if (next != null || hasNext()) {
current = next;
next = null;
return current.getName();
}
throw new NoSuchElementException();
}
@Override
public InputStream open() {
try {
return new FileInputStream(current);
} catch (final FileNotFoundException e) {
throw new ResourceFinderException(e);
}
}
@Override
public void reset() {
throw new UnsupportedOperationException();
}
});
}
}
use of org.glassfish.jersey.server.internal.AbstractResourceFinderAdapter 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();
}
});
}
}
Aggregations