View Javadoc

1   /*
2    * $Id: FilesystemConfigurationIO.java,v 1.13 2006/01/12 17:10:50 tymoteusz Exp $
3    * 
4    */ 
5    
6   package net.sourceforge.jdbdump.connect;
7   
8   import java.io.FileInputStream;
9   import java.io.FileNotFoundException;
10  import java.io.FileOutputStream;
11  import java.io.IOException;
12  import java.io.InputStream;
13  import java.io.OutputStream;
14  import java.util.Properties;
15  
16  /***
17   * This is an implementation of ConfigurationIO abstract class, which is ment to be use for accessing configuration
18   * data stored in file on local filesystem. 
19   * @author tymoteusz
20   * @see ConfigurationIO
21   */
22  public class FilesystemConfigurationIO extends ConfigurationIO {
23  
24  	protected String filename; 
25  	
26  	/***
27  	 * Constructor which uses default system filename (taken from system properties) for 
28  	 * configuration file.
29  	 * 
30  	 * @throws IOException if cannot load configuration data due to I/O problems.
31  	 */
32  	public FilesystemConfigurationIO() throws IOException{
33  		Properties props = new Properties();
34  		props.load(new FileInputStream("app.properties"));// if it doesn't work, use: src/resources/app.properties		
35  		filename = props.getProperty("FilesystemConfigurationIO.filename");
36  	}
37  	
38  	/***
39  	 * Constructor with explicitly specified filename of configuration file
40  	 * 
41  	 * @param filename name of a file on the local filesystem, where configuration is stored
42  	 * @throws IOException if reading data from configuration file fails.
43  	 */
44  	public FilesystemConfigurationIO(String filename) throws IOException{
45  		this.filename = filename;
46  	}
47  
48  	/***
49  	 * Implements method for gaining InputStream access to data through a file on local filesystem.
50  	 * Filename is determined by filename variable set with constructor.
51  	 * @throws FileNotFoundException 
52  	 * @see #FilesystemConfigurationIO(String)
53  	 * @see ConfigurationIO#save() 
54  	 */
55  	protected InputStream getInputStream(){
56  		InputStream input;
57  		try {
58  			input = new FileInputStream(filename);
59  		} catch (FileNotFoundException e) {
60  			input = null;	// create new file?
61  		}
62  		return input;
63  	}
64  
65  	/***
66  	 * Implements method for gaining OutputStream access to data through a file on local filesystem.
67  	 * Filename is determined by filename variable set with constructor.
68  	 * @see #FilesystemConfigurationIO(String)
69  	 * @see ConfigurationIO#save() 
70  	 */
71  	protected OutputStream getOutputStream() throws FileNotFoundException{
72  		return new FileOutputStream(filename);
73  	}
74  }