Package com.optum.sourcehawk.core.utils
Class ModifiableProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<Object,Object>
-
- java.util.Properties
-
- com.optum.sourcehawk.core.utils.ModifiableProperties
-
- All Implemented Interfaces:
Serializable,Cloneable,Map<Object,Object>
public class ModifiableProperties extends Properties
Modified from original source: https://www.dreamincode.net/forums/topic/53734-java-code-to-modify-properties-file-and-preserve-comments/- Author:
- Walt F - https://www.dreamincode.net/forums/user/320878-waltf/, Brian Wyka
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.Properties
defaults
-
-
Constructor Summary
Constructors Constructor Description ModifiableProperties()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String keyString, String value)Add a Property to the end of the CommentedProperties.voidaddLine(String line)Add a comment or blank line or comment to the end of the CommentedProperties.static ModifiablePropertiescreate(InputStream inputStream)Create an instance and load the input streamvoidload(InputStream inputStream)Load properties from the specified InputStream.voidstore(Writer writer, String header)Write the properties to the specified OutputStream.-
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, keys, keySet, list, list, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
-
-
-
Method Detail
-
create
public static ModifiableProperties create(InputStream inputStream) throws IOException
Create an instance and load the input stream- Parameters:
inputStream- the input stream to load- Returns:
- the properties
- Throws:
IOException- if an error occurs loading the input stream
-
load
public void load(InputStream inputStream) throws IOException
Load properties from the specified InputStream. Overload the load method in Properties so we can keep comment and blank lines.- Overrides:
loadin classProperties- Parameters:
inputStream- the input stream to read- Throws:
IOException
-
store
public void store(Writer writer, String header) throws IOException
Write the properties to the specified OutputStream.Overloads the store method in Properties so we can put back comment and blank lines.
- Overrides:
storein classProperties- Parameters:
writer- the writer to use for storingheader- Ignored, here for compatibility w/ Properties.- Throws:
IOException
-
add
public void add(String keyString, String value)
Add a Property to the end of the CommentedProperties.- Parameters:
keyString- The Property key.value- The value of this Property.
-
addLine
public void addLine(String line)
Add a comment or blank line or comment to the end of the CommentedProperties.- Parameters:
line- The string to add to the end, make sure this is a comment or a 'whitespace' line.
-
-