Class LayoutPreservingProperties
- java.lang.Object
- 
- java.util.Dictionary<K,V>
- 
- java.util.Hashtable<java.lang.Object,java.lang.Object>
- 
- java.util.Properties
- 
- org.apache.tools.ant.util.LayoutPreservingProperties
 
 
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.Cloneable,- java.util.Map<java.lang.Object,java.lang.Object>
 
 public class LayoutPreservingProperties extends java.util.PropertiesA Properties collection which preserves comments and whitespace present in the input stream from which it was loaded. The class defers the usual work of the java.util.Properties class to there, but it also keeps track of the contents of the input stream from which it was loaded (if applicable), so that it can write out the properties in as close a form as possible to the input. If no changes occur to property values, the output should be the same as the input, except for the leading date stamp, as normal for a properties file. Properties added are appended to the file. Properties whose values are changed are changed in place. Properties that are removed are excised. If the removeCommentsflag is set, then the comments immediately preceding the property are also removed.If a second set of properties is loaded into an existing set, the lines of the second set are added to the end. Note however, that if a property already stored is present in a stream subsequently loaded, then that property is removed before the new value is set. For example, consider the file # the first line alpha=one # the second line beta=two This file is loaded, and then the following is also loaded into the same LayoutPreservingPropertiesobject# association beta=band # and finally gamma=rays The resulting collection sequence of logical lines depends on whether or not removeCommentswas set at the time the second stream is loaded. If it is set, then the resulting list of lines is# the first line alpha=one # association beta=band # and finally gamma=rays If the flag is not set, then the comment "the second line" is retained, although the key-value pair beta=twois removed.- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description LayoutPreservingProperties()Create a new, empty, Properties collection, with no defaults.LayoutPreservingProperties(java.util.Properties defaults)Create a new, empty, Properties collection, with the specified defaults.
 - 
Method SummaryModifier and Type Method Description voidclear()java.lang.Objectclone()booleanisRemoveComments()Returnstrueif comments are removed along with properties, orfalseotherwise.voidlistLines(java.io.PrintStream out)Echo the lines of the properties (including blanks and comments) to the stream.voidload(java.io.InputStream inStream)java.lang.Objectput(java.lang.Object key, java.lang.Object value)java.lang.Objectremove(java.lang.Object key)voidsaveAs(java.io.File dest)Save the properties to a file.java.lang.ObjectsetProperty(java.lang.String key, java.lang.String value)voidsetRemoveComments(boolean val)Sets the behaviour for comments accompanying properties that are being removed.voidstore(java.io.OutputStream out, java.lang.String header)- 
Methods inherited from class java.util.Propertiescompute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, loadFromXML, merge, propertyNames, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, save, size, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
 
- 
 
- 
- 
- 
Constructor Detail- 
LayoutPreservingPropertiespublic LayoutPreservingProperties() Create a new, empty, Properties collection, with no defaults.
 - 
LayoutPreservingPropertiespublic LayoutPreservingProperties(java.util.Properties defaults) Create a new, empty, Properties collection, with the specified defaults.- Parameters:
- defaults- the default property values
 
 
- 
 - 
Method Detail- 
isRemoveCommentspublic boolean isRemoveComments() Returnstrueif comments are removed along with properties, orfalseotherwise. Iftrue, then when a property is removed, the comment preceding it in the original file is removed also.- Returns:
- trueif leading comments are removed when a property is removed;- falseotherwise
 
 - 
setRemoveCommentspublic void setRemoveComments(boolean val) Sets the behaviour for comments accompanying properties that are being removed. Iftrue, then when a property is removed, the comment preceding it in the original file is removed also.- Parameters:
- val-- trueif leading comments are to be removed when a property is removed;- falseotherwise
 
 - 
loadpublic void load(java.io.InputStream inStream) throws java.io.IOException- Overrides:
- loadin class- java.util.Properties
- Throws:
- java.io.IOException
 
 - 
putpublic java.lang.Object put(java.lang.Object key, java.lang.Object value) throws java.lang.NullPointerException- Specified by:
- putin interface- java.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
- putin class- java.util.Properties
- Throws:
- java.lang.NullPointerException
 
 - 
setPropertypublic java.lang.Object setProperty(java.lang.String key, java.lang.String value) throws java.lang.NullPointerException- Overrides:
- setPropertyin class- java.util.Properties
- Throws:
- java.lang.NullPointerException
 
 - 
clearpublic void clear() - Specified by:
- clearin interface- java.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
- clearin class- java.util.Properties
 
 - 
removepublic java.lang.Object remove(java.lang.Object key) - Specified by:
- removein interface- java.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
- removein class- java.util.Properties
 
 - 
clonepublic java.lang.Object clone() - Overrides:
- clonein class- java.util.Properties
 
 - 
listLinespublic void listLines(java.io.PrintStream out) Echo the lines of the properties (including blanks and comments) to the stream.- Parameters:
- out- the stream to write to
 
 - 
saveAspublic void saveAs(java.io.File dest) throws java.io.IOExceptionSave the properties to a file.- Parameters:
- dest- the file to write to
- Throws:
- java.io.IOException- if save fails
 
 - 
storepublic void store(java.io.OutputStream out, java.lang.String header) throws java.io.IOException- Overrides:
- storein class- java.util.Properties
- Throws:
- java.io.IOException
 
 
- 
 
-