org.springframework.util
Class DefaultPropertiesPersister

java.lang.Object
  extended byorg.springframework.util.DefaultPropertiesPersister
All Implemented Interfaces:
PropertiesPersister

public class DefaultPropertiesPersister
extends java.lang.Object
implements PropertiesPersister

Default implementation of the PropertiesPersister interface. Provides java.util.Properties' native parsing.

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: You can only load files using the ISO-8859-1 charset there.

Due to the fact that java.util.Properties' own load and store methods are implemented in a completely unextensible fashion, the persistence code had to be copied and pasted into this class, allowing to specify any Reader or Writer.

All persistence code in this class is subject to the license of the original java.util.Properties file. The unextensible code there should be permission enough to copy and paste it here.

Since:
10.03.2004
Author:
Juergen Hoeller
See Also:
Properties

Field Summary
protected static char[] hexDigit
          A table of hex digits
static java.lang.String keyValueSeparators
           
static java.lang.String specialSaveChars
           
static java.lang.String strictKeyValueSeparators
           
static java.lang.String whiteSpaceChars
           
 
Constructor Summary
DefaultPropertiesPersister()
           
 
Method Summary
protected  boolean continueLine(java.lang.String line)
          Return true if the given line is a line that must be appended to the next line.
 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.
protected  java.lang.String loadConvert(java.lang.String theString)
          Convert encoded \uxxxx to unicode chars and changes special saved chars to their original forms.
protected  java.lang.String saveConvert(java.lang.String theString, boolean escapeSpace)
          Convert unicodes to encoded \uxxxx and writes out any of the characters in specialSaveChars with a preceding slash
 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.
protected  char toHex(int nibble)
          Convert a nibble to a hex character.
protected  void writeln(java.io.BufferedWriter bw, java.lang.String s)
          Write the given string to the given writer, following it up with a new line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

keyValueSeparators

public static final java.lang.String keyValueSeparators
See Also:
Constant Field Values

strictKeyValueSeparators

public static final java.lang.String strictKeyValueSeparators
See Also:
Constant Field Values

specialSaveChars

public static final java.lang.String specialSaveChars
See Also:
Constant Field Values

whiteSpaceChars

public static final java.lang.String whiteSpaceChars
See Also:
Constant Field Values

hexDigit

protected static final char[] hexDigit
A table of hex digits

Constructor Detail

DefaultPropertiesPersister

public DefaultPropertiesPersister()
Method Detail

load

public void load(java.util.Properties props,
                 java.io.InputStream is)
          throws java.io.IOException
Description copied from interface: PropertiesPersister
Load properties from the given InputStream into the given Properties object.

Specified by:
load in interface PropertiesPersister
Parameters:
props - the Properties object to load into
is - the InputStream to load from
Throws:
java.io.IOException - in case of I/O errors
See Also:
Properties.load(java.io.InputStream)

load

public void load(java.util.Properties props,
                 java.io.Reader reader)
          throws java.io.IOException
Description copied from interface: PropertiesPersister
Load properties from the given Reader into the given Properties object.

Specified by:
load in interface PropertiesPersister
Parameters:
props - the Properties object to load into
reader - the Reader to load from
Throws:
java.io.IOException - in case of I/O errors

continueLine

protected boolean continueLine(java.lang.String line)
Return true if the given line is a line that must be appended to the next line.


loadConvert

protected java.lang.String loadConvert(java.lang.String theString)
Convert encoded \uxxxx to unicode chars and changes special saved chars to their original forms.


store

public void store(java.util.Properties props,
                  java.io.OutputStream os,
                  java.lang.String header)
           throws java.io.IOException
Description copied from interface: PropertiesPersister
Write the contents of the given Properties object to the given OutputStream.

Specified by:
store in interface PropertiesPersister
Parameters:
props - the Properties object to store
os - the OutputStream to write to
header - the description of the property list
Throws:
java.io.IOException - in case of I/O errors
See Also:
Properties.store(java.io.OutputStream, java.lang.String)

store

public void store(java.util.Properties props,
                  java.io.Writer writer,
                  java.lang.String header)
           throws java.io.IOException
Description copied from interface: PropertiesPersister
Write the contents of the given Properties object to the given Writer.

Specified by:
store in interface PropertiesPersister
Parameters:
props - the Properties object to store
writer - the Writer to write to
header - the description of the property list
Throws:
java.io.IOException - in case of I/O errors

writeln

protected void writeln(java.io.BufferedWriter bw,
                       java.lang.String s)
                throws java.io.IOException
Write the given string to the given writer, following it up with a new line.

Throws:
java.io.IOException

saveConvert

protected java.lang.String saveConvert(java.lang.String theString,
                                       boolean escapeSpace)
Convert unicodes to encoded \uxxxx and writes out any of the characters in specialSaveChars with a preceding slash


toHex

protected char toHex(int nibble)
Convert a nibble to a hex character.

Parameters:
nibble - the nibble to convert


Copyright (C) 2003-2004 The Spring Framework Project.