public static StreamIterator create(URL url, Filter filter) throws IOException { String urlString = url.toString(); if (urlString.endsWith("!/")) { urlString = urlString.substring(4); urlString = urlString.substring(0, urlString.length() - 2); url = new URL(urlString); } if (!urlString.endsWith("/")) { return new JarIterator(url.openStream(), filter); } else { DirectoryIteratorFactory factory = registry.get(url.getProtocol()); if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol()); return factory.create(url, filter); } }
public void scanArchives(URL... urls) { for (URL url : urls) { Filter filter = new Filter() { public boolean accepts(String filename) { if (filename.endsWith(".class")) { if (filename.startsWith("/")) filename = filename.substring(1); if (!ignoreScan(filename.replace('/', '.'))) return true; // System.out.println("IGNORED: " + filename); } return false; } }; try { StreamIterator it = IteratorFactory.create(url, filter); InputStream stream; while ((stream = it.next()) != null) scanClass(stream); } catch (Exception e) { e.printStackTrace(); } } }
public InputStream next() { if (closed || (next == null && !initial)) return null; setNext(); if (next == null) return null; return new InputStreamWrapper(jar); }
/** * Scan a url that represents an "archive" this is a classpath directory or jar file * * @param urls variable list of URLs to scan as archives * @throws IOException */ public void scanArchives(URL... urls) throws IOException { for (URL url : urls) { Filter filter = new Filter() { public boolean accepts(String filename) { if (filename.endsWith(".class")) { if (filename.startsWith("/")) filename = filename.substring(1); if (!ignoreScan(filename.replace('/', '.'))) return true; //System.out.println("IGNORED: " + filename); } return false; } }; StreamIterator it = IteratorFactory.create(url, filter); InputStream stream; while ((stream = it.next()) != null) scanClass(stream); } }
public StreamIterator create(URL url, Filter filter) throws IOException { File f = new File(url.getPath()); if (f.isDirectory()) { return new FileIterator(f, filter); } else { return new JarIterator(url.openStream(), filter); } } }
protected static void create(List list, File dir, Filter filter) throws Exception { File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { create(list, files[i], filter); } else { if (filter == null || filter.accepts(files[i].getAbsolutePath())) { list.add(files[i]); } } } }
private void setNext() { initial = true; try { if (next != null) jar.closeEntry(); next = null; do { next = jar.getNextJarEntry(); } while (next != null && (next.isDirectory() || (filter == null || !filter.accepts(next.getName())))); if (next == null) { close(); } } catch (IOException e) { throw new RuntimeException("failed to browse jar", e); } }
DirectoryIteratorFactory factory = registry.get(url.getProtocol()); if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol()); return factory.create(url, filter);
protected static void create(List list, File dir, Filter filter) throws Exception { create(list, dir, filter, dir.getCanonicalPath()); } protected static void create(List list, File dir, Filter filter, String prefix) throws Exception
public static StreamIterator create(URL url, Filter filter) throws IOException { String urlString = url.toString(); if (urlString.endsWith("!/")) { urlString = urlString.substring(4); urlString = urlString.substring(0, urlString.length() - 2); url = new URL(urlString); } if (!urlString.endsWith("/")) { return new JarIterator(url.openStream(), filter); } else { DirectoryIteratorFactory factory = registry.get(url.getProtocol()); if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol()); return factory.create(url, filter); } } }
public StreamIterator create(URL url, Filter filter) throws IOException { // See http://weblogs.java.net/blog/2007/04/25/how-convert-javaneturl-javaiofile File f; try { f = new File(url.toURI()); } catch (URISyntaxException e) { f = new File(url.getPath()); } if (f.isDirectory()) { return new FileIterator(f, filter); } else { return new JarIterator(url.openStream(), filter); } } }
public InputStream next() { if (closed || (next == null && !initial)) return null; setNext(); if (next == null) return null; return new InputStreamWrapper(jar); }
protected static void create(List list, File dir, Filter filter, String prefix) throws Exception { File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { create(list, files[i], filter, prefix); } else { String path = files[i].getCanonicalPath(); String relativePath = path.substring(prefix.length() + 1); if (File.separatorChar == '\\') relativePath = relativePath.replace('\\', '/'); if (filter == null || filter.accepts(relativePath)) { list.add(files[i]); } } } }
private void setNext() { initial = true; try { if (next != null) jar.closeEntry(); next = null; do { next = jar.getNextJarEntry(); } while (next != null && (next.isDirectory() || (filter == null || !filter.accepts(next.getName())))); if (next == null) { close(); } } catch (IOException e) { throw new RuntimeException("failed to browse jar", e); } }
public FileIterator(File file, Filter filter) { files = new ArrayList(); try { create(files, file, filter); } catch (Exception e) { throw new RuntimeException(e); } }
public static StreamIterator create(URL url, Filter filter) throws IOException { String urlString = url.toString(); if (urlString.endsWith("!/")) { urlString = urlString.substring(4); urlString = urlString.substring(0, urlString.length() - 2); url = new URL(urlString); } if (!urlString.endsWith("/")) { return new JarIterator(url.openStream(), filter); } else { DirectoryIteratorFactory factory = registry.get(url.getProtocol()); if (factory == null) throw new IOException("Unable to scan directory of protocol: " + url.getProtocol()); return factory.create(url, filter); } } }
private static void scanURLs(URL[] urls, ServletContext servletContext) throws PragmatachException { try { if (null != servletContext) { final PluginFilter pluginFilter = new PluginFilter(); if ((null != urls) && (urls.length > 0)) { for (final URL url : urls) { if (null != url) { final StreamIterator streamIterator = IteratorFactory.create(url, pluginFilter); InputStream inputStream; while (null != (inputStream = streamIterator.next())) { final PluginDescriptor plugin = new PluginDescriptor(url, inputStream, servletContext); logger.info("Found plugin: " + plugin.getName()); plugins.put(plugin.getName(), plugin); inputStream.close(); } } } } } } catch (final Exception e) { throw new PragmatachException("Exception in scanURLs", e); } }
public FileIterator(File file, Filter filter) { files = new ArrayList(); try { create(files, file, filter); } catch (Exception e) { throw new RuntimeException(e); } } protected static void create(List list, File dir, Filter filter) throws Exception