1 /* 2 * File: FileListEnumerator.java 3 * 4 * A subclass of Enumeration used in conjunction with Concatenate.java 5 * 6 */ 7 8 import java.util.Enumeration; 9 import java.io.InputStream; 10 import java.util.NoSuchElementException; 11 import java.io.FileInputStream; 12 import java.io.FileNotFoundException; 13 14 class FileListEnumerator implements Enumeration { 15 16 String[] listOfFiles; 17 int current = 0; 18 19 FileListEnumerator( String[] listOfFiles ) { 20 this.listOfFiles = listOfFiles; 21 } 22 23 public boolean hasMoreElements() { 24 return ( current < listOfFiles.length ); 25 } 26 27 public Object nextElement() { 28 InputStream in = null; 29 if ( !hasMoreElements() ) 30 throw new NoSuchElementException( "No more files!" ); 31 else { 32 try { 33 String nextElement = listOfFiles[ current++ ]; 34 in = new FileInputStream( nextElement ); 35 } catch ( FileNotFoundException e ) { 36 System.out.println( "ListOfFiles: " + e ); 37 } 38 } 39 return in; 40 } 41 42 } // end class FileListEnumerator