1 22 package org.jboss.util.file; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.FileNotFoundException ; 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 31 37 public class DirectoryArchiveBrowser implements Iterator 38 { 39 private Iterator files; 40 41 public DirectoryArchiveBrowser(File file, ArchiveBrowser.Filter filter) 42 { 43 ArrayList list = new ArrayList (); 44 try 45 { 46 create(list, file, filter); 47 } 48 catch (Exception e) 49 { 50 throw new RuntimeException (e); 51 } 52 files = list.iterator(); 53 } 54 55 public static void create(List list, File dir, ArchiveBrowser.Filter filter) throws Exception 56 { 57 File [] files = dir.listFiles(); 58 for (int i = 0; i < files.length; i++) 59 { 60 if (files[i].isDirectory()) 61 { 62 create(list, files[i], filter); 63 } 64 else 65 { 66 if (filter.accept(files[i].getAbsolutePath())) 67 { 68 list.add(files[i]); 69 } 70 } 71 } 72 } 73 74 public boolean hasNext() 75 { 76 return files.hasNext(); 77 } 78 79 public Object next() 80 { 81 File fp = (File ) files.next(); 82 try 83 { 84 return new FileInputStream (fp); 85 } 86 catch (FileNotFoundException e) 87 { 88 throw new RuntimeException (e); 89 } 90 } 91 92 public void remove() 93 { 94 throw new RuntimeException ("Illegal operation call"); 95 } 96 97 98 } 99 | Popular Tags |