public class

DefaultPropertiesPersister

extends Object
implements PropertiesPersister
java.lang.Object
   ↳ org.springframework.util.DefaultPropertiesPersister

Class Overview

Default implementation of the 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 lacks up until JDK 1.5: You can only 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).

As of Spring 1.2.2, this implementation also supports properties XML files, through the loadFromXml and storeToXml methods. The default implementations delegate to JDK 1.5's corresponding methods, throwing an exception if running on an older JDK. Those implementations could be subclassed to apply custom XML handling on JDK 1.4, for example.

Summary

Public Constructors
DefaultPropertiesPersister()
Public Methods
void load(Properties props, Reader reader)
Load properties from the given Reader into the given Properties object.
void load(Properties props, InputStream is)
Load properties from the given InputStream into the given Properties object.
void loadFromXml(Properties props, InputStream is)
Load properties from the given XML InputStream into the given Properties object.
void store(Properties props, Writer writer, String header)
Write the contents of the given Properties object to the given Writer.
void store(Properties props, OutputStream os, String header)
Write the contents of the given Properties object to the given OutputStream.
void storeToXml(Properties props, OutputStream os, String header)
Write the contents of the given Properties object to the given XML OutputStream.
void storeToXml(Properties props, OutputStream os, String header, String encoding)
Write the contents of the given Properties object to the given XML OutputStream.
Protected Methods
void doLoad(Properties props, Reader reader)
void doStore(Properties props, Writer writer, String header)
boolean endsWithContinuationMarker(String line)
String escape(String str, boolean isKey)
String unescape(String str)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.util.PropertiesPersister

Public Constructors

public DefaultPropertiesPersister ()

Also: SpringCore

Public Methods

public void load (Properties props, Reader reader)

Also: SpringCore

Load properties from the given Reader into the given Properties object.

Parameters
props the Properties object to load into
reader the Reader to load from
Throws
IOException

public void load (Properties props, InputStream is)

Also: SpringCore

Load properties from the given InputStream into the given Properties object.

Parameters
props the Properties object to load into
is the InputStream to load from
Throws
IOException

public void loadFromXml (Properties props, InputStream is)

Also: SpringCore

Load properties from the given XML InputStream into the given Properties object.

Parameters
props the Properties object to load into
is the InputStream to load from
Throws
IOException

public void store (Properties props, Writer writer, String header)

Also: SpringCore

Write the contents of the given Properties object to the given Writer.

Parameters
props the Properties object to store
writer the Writer to write to
header the description of the property list
Throws
IOException

public void store (Properties props, OutputStream os, String header)

Also: SpringCore

Write the contents of the given Properties object to the given OutputStream.

Parameters
props the Properties object to store
os the OutputStream to write to
header the description of the property list
Throws
IOException

public void storeToXml (Properties props, OutputStream os, String header)

Also: SpringCore

Write the contents of the given Properties object to the given XML OutputStream.

Parameters
props the Properties object to store
os the OutputStream to write to
header the description of the property list
Throws
IOException

public void storeToXml (Properties props, OutputStream os, String header, String encoding)

Also: SpringCore

Write the contents of the given Properties object to the given XML OutputStream.

Parameters
props the Properties object to store
os the OutputStream to write to
header the description of the property list
encoding the encoding to use
Throws
IOException

Protected Methods

protected void doLoad (Properties props, Reader reader)

Also: SpringCore

Throws
IOException

protected void doStore (Properties props, Writer writer, String header)

Also: SpringCore

Throws
IOException

protected boolean endsWithContinuationMarker (String line)

Also: SpringCore

protected String escape (String str, boolean isKey)

Also: SpringCore

protected String unescape (String str)

Also: SpringCore