public class DefaultPropertiesPersister extends java.lang.Object implements PropertiesPersister
PropertiesPersister
interface.
Follows the native parsing of java.util.Properties
.
Allows for reading from any Reader and writing to any Writer, for example
to specify a charset for a properties file. This is a capability that standard
java.util.Properties
unfortunately lacked up until JDK 1.5:
You were only able to load files using the ISO-8859-1 charset there.
Loading from and storing to a stream delegates to Properties.load
and Properties.store
, respectively, to be fully compatible with
the Unicode conversion as implemented by the JDK Properties class. On JDK 1.6,
Properties.load/store
will also be used for readers/writers,
effectively turning this class into a plain backwards compatibility adapter.
The persistence code that works with Reader/Writer follows the JDK's parsing strategy but does not implement Unicode conversion, because the Reader/Writer should already apply proper decoding/encoding of characters. If you use prefer to escape unicode characters in your properties files, do not specify an encoding for a Reader/Writer (like ReloadableResourceBundleMessageSource's "defaultEncoding" and "fileEncodings" properties).
Properties
,
Properties.load(java.io.Reader)
,
Properties.store(java.io.Writer, java.lang.String)
Modifier and Type | Field and Description |
---|---|
private static boolean |
loadFromReaderAvailable |
private static boolean |
storeToWriterAvailable |
Constructor and Description |
---|
DefaultPropertiesPersister() |
Modifier and Type | Method and Description |
---|---|
protected void |
doLoad(java.util.Properties props,
java.io.Reader reader) |
protected void |
doStore(java.util.Properties props,
java.io.Writer writer,
java.lang.String header) |
protected boolean |
endsWithContinuationMarker(java.lang.String line) |
protected java.lang.String |
escape(java.lang.String str,
boolean isKey) |
void |
load(java.util.Properties props,
java.io.InputStream is)
Load properties from the given InputStream into the given
Properties object.
|
void |
load(java.util.Properties props,
java.io.Reader reader)
Load properties from the given Reader into the given
Properties object.
|
void |
loadFromXml(java.util.Properties props,
java.io.InputStream is)
Load properties from the given XML InputStream into the
given Properties object.
|
void |
store(java.util.Properties props,
java.io.OutputStream os,
java.lang.String header)
Write the contents of the given Properties object to the
given OutputStream.
|
void |
store(java.util.Properties props,
java.io.Writer writer,
java.lang.String header)
Write the contents of the given Properties object to the
given Writer.
|
void |
storeToXml(java.util.Properties props,
java.io.OutputStream os,
java.lang.String header)
Write the contents of the given Properties object to the
given XML OutputStream.
|
void |
storeToXml(java.util.Properties props,
java.io.OutputStream os,
java.lang.String header,
java.lang.String encoding)
Write the contents of the given Properties object to the
given XML OutputStream.
|
protected java.lang.String |
unescape(java.lang.String str) |
private static final boolean loadFromReaderAvailable
private static final boolean storeToWriterAvailable
public void load(java.util.Properties props, java.io.InputStream is) throws java.io.IOException
PropertiesPersister
load
in interface PropertiesPersister
props
- the Properties object to load intois
- the InputStream to load fromjava.io.IOException
- in case of I/O errorsProperties.load(java.io.Reader)
public void load(java.util.Properties props, java.io.Reader reader) throws java.io.IOException
PropertiesPersister
load
in interface PropertiesPersister
props
- the Properties object to load intoreader
- the Reader to load fromjava.io.IOException
- in case of I/O errorsprotected void doLoad(java.util.Properties props, java.io.Reader reader) throws java.io.IOException
java.io.IOException
protected boolean endsWithContinuationMarker(java.lang.String line)
protected java.lang.String unescape(java.lang.String str)
public void store(java.util.Properties props, java.io.OutputStream os, java.lang.String header) throws java.io.IOException
PropertiesPersister
store
in interface PropertiesPersister
props
- the Properties object to storeos
- the OutputStream to write toheader
- the description of the property listjava.io.IOException
- in case of I/O errorsProperties.store(java.io.Writer, java.lang.String)
public void store(java.util.Properties props, java.io.Writer writer, java.lang.String header) throws java.io.IOException
PropertiesPersister
store
in interface PropertiesPersister
props
- the Properties object to storewriter
- the Writer to write toheader
- the description of the property listjava.io.IOException
- in case of I/O errorsprotected void doStore(java.util.Properties props, java.io.Writer writer, java.lang.String header) throws java.io.IOException
java.io.IOException
protected java.lang.String escape(java.lang.String str, boolean isKey)
public void loadFromXml(java.util.Properties props, java.io.InputStream is) throws java.io.IOException
PropertiesPersister
loadFromXml
in interface PropertiesPersister
props
- the Properties object to load intois
- the InputStream to load fromjava.io.IOException
- in case of I/O errorsProperties.loadFromXML(java.io.InputStream)
public void storeToXml(java.util.Properties props, java.io.OutputStream os, java.lang.String header) throws java.io.IOException
PropertiesPersister
storeToXml
in interface PropertiesPersister
props
- the Properties object to storeos
- the OutputStream to write toheader
- the description of the property listjava.io.IOException
- in case of I/O errorsProperties.storeToXML(java.io.OutputStream, String)
public void storeToXml(java.util.Properties props, java.io.OutputStream os, java.lang.String header, java.lang.String encoding) throws java.io.IOException
PropertiesPersister
storeToXml
in interface PropertiesPersister
props
- the Properties object to storeos
- the OutputStream to write toheader
- the description of the property listencoding
- the encoding to usejava.io.IOException
- in case of I/O errorsProperties.storeToXML(java.io.OutputStream, String, String)