public class

SmartProperties

extends Properties
java.lang.Object
   ↳ java.util.Dictionary<K, V>
     ↳ java.util.Hashtable<K, V>
       ↳ java.util.Properties
         ↳ com.microstrategy.utils.SmartProperties

Class Overview

SmartProperties simplifies file persistence handling by using the FileFinder to locate the properties file. Resolution of the file path is described in setPath(String).

Summary

[Expand]
Inherited Fields
From class java.util.Properties
Public Constructors
SmartProperties(String propertiesFilePath)
Constructor.
SmartProperties(String propertiesFilePath, Properties defaultProperties)
Public Methods
synchronized boolean canSave()
synchronized InputStream getInputStream()
Returns the InputStream for the properties file.
synchronized String getPath()
synchronized Enumeration<Object> keys()
synchronized void load()
synchronized void save()
Persists the state of the properties object.
synchronized void save(String headerComment)
Persists the state of the properties object.
synchronized void setPath(String propertiesFilePath)

Sets the path of the properties file.

Protected Methods
synchronized OutputStream getOutputStream()
Returns the OutputStream for the properties file.
[Expand]
Inherited Methods
From class java.util.Properties
From class java.util.Hashtable
From class java.util.Dictionary
From class java.lang.Object
From interface java.util.Map

Public Constructors

public SmartProperties (String propertiesFilePath)

Constructor. Resolution of the file path is described in setPath(String).

Parameters
propertiesFilePath Location of the properties file.
Throws
IOException Thrown when error occurs during loading the properties file.

public SmartProperties (String propertiesFilePath, Properties defaultProperties)

Throws
IOException

Public Methods

public synchronized boolean canSave ()

Returns
  • whether the properties can be persisted by checking the security manager as well as file permissions

public synchronized InputStream getInputStream ()

Returns the InputStream for the properties file. Please invoke one of the save methods to synchronize changes first.

Returns
  • the InputStream for the properties file.
Throws
FileNotFoundException if the properties file could not be found

public synchronized String getPath ()

Returns
  • The file path of the properties file.

public synchronized Enumeration<Object> keys ()

public synchronized void load ()

Throws
IOException

public synchronized void save ()

Persists the state of the properties object. If the properties object isEmpty, save will delete the properties file.

Throws
IOException When error occurs during storing the states into the properties file.

public synchronized void save (String headerComment)

Persists the state of the properties object. If the properties object isEmpty, save will delete the properties file.

Parameters
headerComment Preamble comment in the properties file.
Throws
IOException When error occurs during storing the states into the properties file.

public synchronized void setPath (String propertiesFilePath)

Sets the path of the properties file. This will not load new properties from the file, nor will it save the current state. If the file name omits the ".properties" suffix, one will be appended.

Resolution steps as follows:

  • Fully qualified path provided. A new file will be created if it does not already exist.
  • Relative path or file name provided. Attempt classpath lookup - file must not be inside a JAR.

Parameters
propertiesFilePath Location of the properties file.
Throws
IOException Thrown when error occurs during loading the properties file.
FileNotFoundException if file could not be located

Protected Methods

protected synchronized OutputStream getOutputStream ()

Returns the OutputStream for the properties file.

Returns
  • the OutputStream for the properties file.
Throws
FileNotFoundException if the properties file could not be found