1 4 5 package org.objectweb.perseus.fos.lib; 6 7 import org.objectweb.perseus.fos.api.FosException; 8 9 import java.io.File ; 10 import java.io.FilenameFilter ; 11 import java.util.Iterator ; 12 import java.util.NoSuchElementException ; 13 14 18 public class FosExtension implements Iterator , FilenameFilter { 19 private String [] fnList; 20 private int next = 0; 21 22 private FosExtension() { 23 } 24 25 29 FosExtension(String dn) throws FosException { 30 File fod = new File (dn); 31 if (!fod.exists()) 32 fnList = null; 33 else if (!fod.isDirectory()) { 34 fnList = null; 35 throw new FosException("Wrong directory name: " + dn); 36 } 37 fnList = fod.list(this); 38 } 39 40 43 public boolean hasNext() { 44 if (fnList == null) 45 return false; 46 return next < fnList.length; 47 } 48 49 52 public Object next() throws NoSuchElementException { 53 if (next >= fnList.length) 54 throw new NoSuchElementException (); 55 return fnList[next++]; 56 } 57 58 61 public void remove() 62 throws UnsupportedOperationException , IllegalStateException { 63 throw new UnsupportedOperationException (); 64 } 65 66 70 public boolean accept(File dir, String name) { 71 if (name.endsWith(FosObjectFile.WRITESUFFIX)) 72 return false; 73 if (name.endsWith(FosObjectFile.DELETSUFFIX)) 74 return false; 75 File f = new File (dir.getPath() + File.separator + name); 76 return f.isFile(); 77 } 78 } | Popular Tags |