Package com.microstrategy.utils
Class SmartProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<java.lang.Object,java.lang.Object>
-
- java.util.Properties
-
- com.microstrategy.utils.SmartProperties
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.Object>
public class SmartProperties extends java.util.Properties
SmartProperties simplifies file persistence handling by using theFileFinder
to locate the properties file. Resolution of the file path is described insetPath(String)
.- Since:
- MicroStrategy Web 7.3.1 or earlier
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SmartProperties(java.lang.String propertiesFilePath)
Constructor.SmartProperties(java.lang.String propertiesFilePath, java.util.Properties defaultProperties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canSave()
java.io.InputStream
getInputStream()
Returns theInputStream
for the properties file.protected java.io.OutputStream
getOutputStream()
Returns theOutputStream
for the properties file.java.lang.String
getPath()
java.util.Enumeration<java.lang.Object>
keys()
void
load()
void
save()
Persists the state of the properties object.void
save(java.lang.String headerComment)
Persists the state of the properties object.void
setPath(java.lang.String propertiesFilePath)
Sets the path of the properties file.-
Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Constructor Detail
-
SmartProperties
public SmartProperties(java.lang.String propertiesFilePath) throws java.io.IOException
Constructor. Resolution of the file path is described insetPath(String)
.- Parameters:
propertiesFilePath
- Location of the properties file.- Throws:
java.io.IOException
- Thrown when error occurs during loading the properties file.
-
SmartProperties
public SmartProperties(java.lang.String propertiesFilePath, java.util.Properties defaultProperties) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
setPath
public void setPath(java.lang.String propertiesFilePath) throws java.io.IOException
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:
java.io.IOException
- Thrown when error occurs during loading the properties file.java.io.FileNotFoundException
- if file could not be located
-
getPath
public java.lang.String getPath()
- Returns:
- The file path of the properties file.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.FileNotFoundException
Returns theInputStream
for the properties file. Please invoke one of thesave
methods to synchronize changes first.- Returns:
- the
InputStream
for the properties file. - Throws:
java.io.FileNotFoundException
- if the properties file could not be found
-
getOutputStream
protected java.io.OutputStream getOutputStream() throws java.io.FileNotFoundException
Returns theOutputStream
for the properties file.- Returns:
- the
OutputStream
for the properties file. - Throws:
java.io.FileNotFoundException
- if the properties file could not be found
-
save
public void save(java.lang.String headerComment) throws java.io.IOException
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:
java.io.IOException
- When error occurs during storing the states into the properties file.
-
save
public void save() throws java.io.IOException
Persists the state of the properties object. If the properties object isEmpty, save will delete the properties file.- Throws:
java.io.IOException
- When error occurs during storing the states into the properties file.
-
canSave
public boolean canSave()
- Returns:
- whether the properties can be persisted by checking the security manager as well as file permissions
- Since:
- MicroStrategy Web 8.0.1
-
load
public void load() throws java.io.IOException
- Throws:
java.io.IOException
-
keys
public java.util.Enumeration<java.lang.Object> keys()
- Overrides:
keys
in classjava.util.Properties
- Since:
- MicroStrategy Web 9.0.0
-
-