1 22 package org.jboss.util.file; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.net.JarURLConnection ; 27 import java.net.URI ; 28 import java.net.URISyntaxException ; 29 import java.net.URL ; 30 import java.util.Iterator ; 31 32 38 public abstract class ArchiveBrowser 39 { 40 public interface Filter 41 { 42 boolean accept(String filename); 43 } 44 45 public static Iterator getBrowser(URL url, Filter filter) 46 { 47 if (url.getProtocol().equals("file")) 48 { 49 File f = null; 50 try 51 { 52 f = new File (new URI (url.toString())); 53 } 54 catch (URISyntaxException e) 55 { 56 throw new RuntimeException ("Not a valid URL: " + url, e); 57 } 58 if (f.isDirectory()) 59 { 60 return new DirectoryArchiveBrowser(f, filter); 61 } 62 else 63 { 64 return new JarArchiveBrowser(f, filter); 65 } 66 } 67 else if (url.getProtocol().startsWith("jar")) 68 { 69 if (url.toString().endsWith("!/")) 70 { 71 try 72 { 73 return new JarArchiveBrowser((JarURLConnection ) url.openConnection(), filter); 74 } 75 catch (IOException e) 76 { 77 throw new RuntimeException ("Unable to browse url: " + url, e); 78 } 79 } 80 else 81 { 82 try 83 { 84 return new JarStreamBrowser(url.openStream(), filter); 85 } 86 catch (IOException e) 87 { 88 throw new RuntimeException ("Unable to browse url: " + url, e); 89 } 90 } 91 92 } 93 else throw new RuntimeException ("Archive browser cannot handle protocol: " + url); 94 } 95 } 96 | Popular Tags |