1 22 package org.jboss.util.property; 23 24 import java.util.Properties ; 25 import java.util.Map ; 26 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.InputStream ; 30 import java.io.BufferedInputStream ; 31 import java.io.IOException ; 32 33 import org.jboss.util.NullArgumentException; 34 35 41 public class FilePropertyReader 42 implements PropertyReader 43 { 44 45 protected String [] filenames; 46 47 53 public FilePropertyReader(String [] filenames) { 54 if (filenames == null) 55 throw new NullArgumentException("filenames"); 56 57 this.filenames = filenames; 58 } 59 60 65 public FilePropertyReader(String filename) { 66 this(new String [] { filename }); 67 } 68 69 77 protected InputStream getInputStream(String filename) throws IOException { 78 File file = new File (filename); 79 return new FileInputStream (file); 80 } 81 82 91 protected void loadProperties(Properties props, String filename) 92 throws IOException 93 { 94 if (filename == null) 95 throw new NullArgumentException("filename"); 96 if (filename.equals("")) 97 throw new IllegalArgumentException ("filename"); 98 99 InputStream in = new BufferedInputStream (getInputStream(filename)); 100 props.load(in); 101 in.close(); 102 } 103 104 112 public Map readProperties() 113 throws PropertyException, IOException 114 { 115 Properties props = new Properties (); 116 117 for (int i=0; i<filenames.length; i++) { 119 loadProperties(props, filenames[i]); 120 } 121 122 return props; 123 } 124 } 125 | Popular Tags |