Package org.apache.openjpa.lib.util
Class FormatPreservingProperties
- java.lang.Object
 - 
- java.util.Dictionary<K,V>
 - 
- java.util.Hashtable<Object,Object>
 - 
- java.util.Properties
 - 
- org.apache.openjpa.lib.util.FormatPreservingProperties
 
 
 
 
 
- 
- All Implemented Interfaces:
 Serializable,Cloneable,Map<Object,Object>
public class FormatPreservingProperties extends Properties
A specialization ofPropertiesthat stores its contents in the same order and with the same formatting as was used to read the contents from an input stream. This is useful because it means that a properties file loaded via this object and then written back out later on will only be different where changes or additions were made. By default, thestore(java.io.OutputStream, java.lang.String)method in this class does not behave the same asProperties.store(java.io.Writer, java.lang.String). You can cause an instance to approximate the behavior ofProperties.store(java.io.Writer, java.lang.String)by invokingsetDefaultEntryDelimiter(char)with=,setAddWhitespaceAfterDelimiter(boolean)withfalse, andsetAllowDuplicates(boolean)withtrue. However, this will only influence how the instance will write new values, not how it will write existing key-value pairs that are modified. In conjunction with a conservative output writer, it is possible to only write to disk changes / additions. This implementation does not permit escaped ' ', '=', ':' characters in key names.- Since:
 - 0.3.3
 - See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFormatPreservingProperties.DuplicateKeyException 
- 
Field Summary
- 
Fields inherited from class java.util.Properties
defaults 
 - 
 
- 
Constructor Summary
Constructors Constructor Description FormatPreservingProperties()FormatPreservingProperties(Properties defaults) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Objectclone()booleangetAddWhitespaceAfterDelimiter()If set totrue, this properties object will add a space after the delimiter character(if the delimiter is not the space character).booleangetAllowDuplicates()If set totrue, duplicate properties are allowed, and the last property setting in the input will overwrite any previous settings.chargetDefaultEntryDelimiter()booleangetInsertTimestamp()If set totrue, this properties object will add a timestamp to the beginning of the file, just after the header (if any) is printed.StringgetProperty(String key)StringgetProperty(String key, String defaultValue)voidload(InputStream in)Loads the properties inin, according to the rules described inProperties.load(java.io.Reader).Objectput(Object key, Object val)voidputAll(Map m)Circumvents the superclassputAll(java.util.Map)implementation, putting all the key-value pairs viaput(java.lang.Object, java.lang.Object).Objectremove(Object key)Removes the key from the bookkeeping collectiotns as well.voidsave(OutputStream out, String header)voidsetAddWhitespaceAfterDelimiter(boolean add)If set totrue, this properties object will add a space after the delimiter character(if the delimiter is not the space character).voidsetAllowDuplicates(boolean allowDuplicates)If set totrue, duplicate properties are allowed, and the last property setting in the input will overwrite any previous settings.voidsetDefaultEntryDelimiter(char defaultEntryDelimiter)The character to use as a delimiter between property keys and values.voidsetInsertTimestamp(boolean insertTimestamp)If set totrue, this properties object will add a timestamp to the beginning of the file, just after the header (if any) is printed.ObjectsetProperty(String key, String value)voidstore(OutputStream out, String header)- 
Methods inherited from class java.util.Properties
compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, list, list, load, loadFromXML, merge, propertyNames, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
FormatPreservingProperties
public FormatPreservingProperties()
 
- 
FormatPreservingProperties
public FormatPreservingProperties(Properties defaults)
 
 - 
 
- 
Method Detail
- 
setDefaultEntryDelimiter
public void setDefaultEntryDelimiter(char defaultEntryDelimiter)
The character to use as a delimiter between property keys and values.- Parameters:
 defaultEntryDelimiter- either ':' or '='
 
- 
getDefaultEntryDelimiter
public char getDefaultEntryDelimiter()
 
- 
setAddWhitespaceAfterDelimiter
public void setAddWhitespaceAfterDelimiter(boolean add)
If set totrue, this properties object will add a space after the delimiter character(if the delimiter is not the space character). Else, this will not add a space. Default value:true. Note thatProperties.store(java.io.Writer, java.lang.String)never writes whitespace. 
- 
getAddWhitespaceAfterDelimiter
public boolean getAddWhitespaceAfterDelimiter()
If set totrue, this properties object will add a space after the delimiter character(if the delimiter is not the space character). Else, this will not add a space. Default value:true. Note thatProperties.store(java.io.Writer, java.lang.String)never writes whitespace. 
- 
setInsertTimestamp
public void setInsertTimestamp(boolean insertTimestamp)
If set totrue, this properties object will add a timestamp to the beginning of the file, just after the header (if any) is printed. Else, this will not add a timestamp. Default value:false. Note thatProperties.store(java.io.Writer, java.lang.String)always writes a timestamp. 
- 
getInsertTimestamp
public boolean getInsertTimestamp()
If set totrue, this properties object will add a timestamp to the beginning of the file, just after the header (if any) is printed. Else, this will not add a timestamp. Default value:false. Note thatProperties.store(java.io.Writer, java.lang.String)always writes a timestamp. 
- 
setAllowDuplicates
public void setAllowDuplicates(boolean allowDuplicates)
If set totrue, duplicate properties are allowed, and the last property setting in the input will overwrite any previous settings. If set tofalse, duplicate property definitions in the input will cause an exception to be thrown duringload(java.io.InputStream). Default value:false. Note thatProperties.store(java.io.Writer, java.lang.String)always allows duplicates. 
- 
getAllowDuplicates
public boolean getAllowDuplicates()
If set totrue, duplicate properties are allowed, and the last property setting in the input will overwrite any previous settings. If set tofalse, duplicate property definitions in the input will cause an exception to be thrown duringload(java.io.InputStream). Default value:false. Note thatProperties.store(java.io.Writer, java.lang.String)always allows duplicates. 
- 
getProperty
public String getProperty(String key)
- Overrides:
 getPropertyin classProperties
 
- 
getProperty
public String getProperty(String key, String defaultValue)
- Overrides:
 getPropertyin classProperties
 
- 
setProperty
public Object setProperty(String key, String value)
- Overrides:
 setPropertyin classProperties
 
- 
putAll
public void putAll(Map m)
Circumvents the superclassputAll(java.util.Map)implementation, putting all the key-value pairs viaput(java.lang.Object, java.lang.Object). 
- 
clear
public void clear()
 
- 
clone
public Object clone()
- Overrides:
 clonein classProperties
 
- 
load
public void load(InputStream in) throws IOException
Loads the properties inin, according to the rules described inProperties.load(java.io.Reader). IfgetAllowDuplicates()returnstrue, this will throw aFormatPreservingProperties.DuplicateKeyExceptionif duplicate property declarations are encountered.- Overrides:
 loadin classProperties- Throws:
 IOException- See Also:
 Properties.load(java.io.Reader)
 
- 
save
public void save(OutputStream out, String header)
- Overrides:
 savein classProperties
 
- 
store
public void store(OutputStream out, String header) throws IOException
- Overrides:
 storein classProperties- Throws:
 IOException
 
 - 
 
 -