|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Dictionary<K,V> java.util.Hashtable<Object,Object> java.util.Properties org.apache.openjpa.lib.util.FormatPreservingProperties
public class FormatPreservingProperties
A specialization of Properties
that 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, the store(java.io.OutputStream, java.lang.String)
method in this class does not
behave the same as Properties.store(java.io.Writer, java.lang.String)
. You can cause an
instance to approximate the behavior of Properties.store(java.io.Writer, java.lang.String)
by invoking setDefaultEntryDelimiter(char)
with =
,
setAddWhitespaceAfterDelimiter(boolean)
with false
, and
setAllowDuplicates(boolean)
with true
. 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.
Nested Class Summary | |
---|---|
static class |
FormatPreservingProperties.DuplicateKeyException
|
Field Summary |
---|
Fields inherited from class java.util.Properties |
---|
defaults |
Constructor Summary | |
---|---|
FormatPreservingProperties()
|
|
FormatPreservingProperties(Properties defaults)
|
Method Summary | |
---|---|
void |
clear()
|
Object |
clone()
|
boolean |
getAddWhitespaceAfterDelimiter()
If set to true , this properties object will add a
space after the delimiter character(if the delimiter is not
the space character). |
boolean |
getAllowDuplicates()
If set to true , duplicate properties are allowed, and
the last property setting in the input will overwrite any previous
settings. |
char |
getDefaultEntryDelimiter()
See setDefaultEntryDelimiter(char) |
boolean |
getInsertTimestamp()
If set to true , this properties object will add a
timestamp to the beginning of the file, just after the header
(if any) is printed. |
String |
getProperty(String key)
|
String |
getProperty(String key,
String defaultValue)
|
void |
load(InputStream in)
Loads the properties in in , according to the rules
described in Properties.load(java.io.Reader) . |
Object |
put(Object key,
Object val)
|
void |
putAll(Map m)
Circumvents the superclass putAll(java.util.Map) implementation,
putting all the key-value pairs via put(java.lang.Object, java.lang.Object) . |
Object |
remove(Object key)
Removes the key from the bookkeeping collectiotns as well. |
void |
save(OutputStream out,
String header)
|
void |
setAddWhitespaceAfterDelimiter(boolean add)
If set to true , this properties object will add a
space after the delimiter character(if the delimiter is not
the space character). |
void |
setAllowDuplicates(boolean allowDuplicates)
If set to true , duplicate properties are allowed, and
the last property setting in the input will overwrite any previous
settings. |
void |
setDefaultEntryDelimiter(char defaultEntryDelimiter)
The character to use as a delimiter between property keys and values. |
void |
setInsertTimestamp(boolean insertTimestamp)
If set to true , this properties object will add a
timestamp to the beginning of the file, just after the header
(if any) is printed. |
Object |
setProperty(String key,
String value)
|
void |
store(OutputStream out,
String header)
|
Methods inherited from class java.util.Properties |
---|
list, list, load, loadFromXML, propertyNames, store, storeToXML, storeToXML, stringPropertyNames |
Methods inherited from class java.util.Hashtable |
---|
contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, rehash, size, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FormatPreservingProperties()
public FormatPreservingProperties(Properties defaults)
Method Detail |
---|
public void setDefaultEntryDelimiter(char defaultEntryDelimiter)
defaultEntryDelimiter
- either ':' or '='public char getDefaultEntryDelimiter()
setDefaultEntryDelimiter(char)
public void setAddWhitespaceAfterDelimiter(boolean add)
true
, 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 that Properties.store(java.io.Writer, java.lang.String)
never writes whitespace.
public boolean getAddWhitespaceAfterDelimiter()
true
, 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 that Properties.store(java.io.Writer, java.lang.String)
never writes whitespace.
public void setInsertTimestamp(boolean insertTimestamp)
true
, 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 that Properties.store(java.io.Writer, java.lang.String)
always writes a timestamp.
public boolean getInsertTimestamp()
true
, 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 that Properties.store(java.io.Writer, java.lang.String)
always writes a timestamp.
public void setAllowDuplicates(boolean allowDuplicates)
true
, duplicate properties are allowed, and
the last property setting in the input will overwrite any previous
settings. If set to false
, duplicate property definitions
in the input will cause an exception to be thrown during load(java.io.InputStream)
.
Default value: false
. Note that Properties.store(java.io.Writer, java.lang.String)
always allows duplicates.
public boolean getAllowDuplicates()
true
, duplicate properties are allowed, and
the last property setting in the input will overwrite any previous
settings. If set to false
, duplicate property definitions
in the input will cause an exception to be thrown during load(java.io.InputStream)
.
Default value: false
. Note that Properties.store(java.io.Writer, java.lang.String)
always allows duplicates.
public String getProperty(String key)
getProperty
in class Properties
public String getProperty(String key, String defaultValue)
getProperty
in class Properties
public Object setProperty(String key, String value)
setProperty
in class Properties
public void putAll(Map m)
putAll(java.util.Map)
implementation,
putting all the key-value pairs via put(java.lang.Object, java.lang.Object)
.
putAll
in interface Map<Object,Object>
putAll
in class Hashtable<Object,Object>
public Object remove(Object key)
remove
in interface Map<Object,Object>
remove
in class Hashtable<Object,Object>
public void clear()
clear
in interface Map<Object,Object>
clear
in class Hashtable<Object,Object>
public Object clone()
clone
in class Hashtable<Object,Object>
public Object put(Object key, Object val)
put
in interface Map<Object,Object>
put
in class Hashtable<Object,Object>
public void load(InputStream in) throws IOException
in
, according to the rules
described in Properties.load(java.io.Reader)
. If getAllowDuplicates()
returns true
, this will throw a FormatPreservingProperties.DuplicateKeyException
if duplicate property declarations are
encountered.
load
in class Properties
IOException
Properties.load(java.io.Reader)
public void save(OutputStream out, String header)
save
in class Properties
public void store(OutputStream out, String header) throws IOException
store
in class Properties
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |