FileDocCategorySizeDatePackage
FileProperties.javaAPI DocExample2474Sat Apr 28 10:22:36 BST 2001com.darwinsys.util

FileProperties

public class FileProperties extends Properties
The FileProperties class extends Properties, "a persistent set of properties [that] can be saved to a stream or loaded from a stream". This subclass attends to all the mundane details of opening the Stream(s) for actually saving and loading the Properties.

This subclass preserves the useful feature that a property list can contain another property list as its "defaults"; this second property list is searched if the property key is not found in the original property list.

author
Ian F. Darwin, ian@darwinsys.com
version
$Id: FileProperties.java,v 1.5 2001/04/28 13:22:37 ian Exp $

Fields Summary
protected String
fileName
protected InputStream
inStr
The InputStream for loading
protected OutputStream
outStr
The OutputStream for loading
Constructors Summary
public FileProperties(String loadsaveFileName)
Construct a FileProperties given a fileName.


	       
	  
	  
		super();
		fileName = loadsaveFileName;
		load();
	
public FileProperties(String loadsaveFileName, Properties defProp)
Construct a FileProperties given a fileName and a list of default properties.

		super(defProp);
		fileName = loadsaveFileName;
		load();
	
Methods Summary
public voidclose()

		try {
			if (inStr != null)
				inStr.close();
			if (outStr != null)
				outStr.close();
		} catch (IOException e) {
			// don't care 
		}
	
public voidload()
Load the properties from the saved filename. If that fails, try again, tacking on the .properties extension


	                 	 
	     
		try {
			if (inStr==null) {
				inStr = new FileInputStream(fileName);
			}
		} catch (FileNotFoundException fnf) {
			if (!fileName.endsWith(".properties")) {
				inStr = new FileInputStream(fileName + ".properties");
				// If we succeeded, remember it:
				fileName += ".properties";
			} else
				// It did end with .properties and failed, re-throw exception.
				throw fnf;
		}
		// now message the superclass code to load the file.
		load(inStr);
	
public voidsave()
Save the properties for later loading.

		if (outStr==null) {
			outStr = new FileOutputStream(fileName);
		}
		// Get the superclass to do most of the work for us.
		store(outStr, "# Written by FileProperties.save() at " + new Date());