org.nuiton.io
Class SortedProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<Object,Object>
          extended by java.util.Properties
              extended by org.nuiton.io.SortedProperties
All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class SortedProperties
extends Properties

Extend Properties to allow alphabetical order. Encoding could also be defined but you must use this class only with Java 1.6.

Author:
ruchaud , tchemit
See Also:
Serialized Form

Field Summary
protected  String defaultEncoding
          l'encoding par defaut a utiliser pour lire et ecrire le properties.
static String ENCODING_ASCII
           
static String ENCODING_DEFAULT
           
static String ENCODING_LATIN1
           
protected  char[] hexDigit
           
protected  boolean removeHeader
          un drapeau pour savoir s'il faut enlever l'entete generere
protected  boolean unicodeLower
          A flag to write unicode using the a lower letter.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
SortedProperties()
           
SortedProperties(Properties defaults)
           
SortedProperties(String defaultEncoding)
           
SortedProperties(String defaultEncoding, boolean removeHeader)
           
SortedProperties(String defaultEncoding, boolean removeHeader, boolean unicodeLower)
           
 
Method Summary
 Enumeration<Object> keys()
           
 SortedProperties load(File src)
          Load all properties from given src file using defined defaultEncoding.
 SortedProperties load(File src, String encoding)
          Load Properties from src file using given defaultEncoding.
protected  String saveConvert(String theString, boolean escapeSpace, boolean escapeUnicode)
           
 void store(File dst)
          Save properties in given dst file using defined defaultEncoding.
 void store(File dst, String encoding)
          Store Properties in output file using given defaultEncoding.
 void store(OutputStream dst)
          Save properties in given stream file.
 void store(OutputStream out, String comments)
           
 void store(Writer writer, String comments)
           
protected  void store0(BufferedWriter bw, String comments, boolean escUnicode)
           
protected  void storeEncode(OutputStream stream, String encoding)
          If encoding is not the default Properties one, we will use a writer to use this custom encoding.
protected  char toHex(int nibble)
          Convert a nibble to a hex character
 void writeComments(BufferedWriter bw, String comments)
           
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, storeToXML, storeToXML, stringPropertyNames
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ENCODING_DEFAULT

public static final String ENCODING_DEFAULT
See Also:
Constant Field Values

ENCODING_LATIN1

public static final String ENCODING_LATIN1
See Also:
Constant Field Values

ENCODING_ASCII

public static final String ENCODING_ASCII
See Also:
Constant Field Values

defaultEncoding

protected String defaultEncoding
l'encoding par defaut a utiliser pour lire et ecrire le properties.


removeHeader

protected boolean removeHeader
un drapeau pour savoir s'il faut enlever l'entete generere


unicodeLower

protected final boolean unicodeLower
A flag to write unicode using the a lower letter.

Example : é instead of é.


hexDigit

protected final char[] hexDigit
Constructor Detail

SortedProperties

public SortedProperties()

SortedProperties

public SortedProperties(String defaultEncoding)

SortedProperties

public SortedProperties(String defaultEncoding,
                        boolean removeHeader)

SortedProperties

public SortedProperties(String defaultEncoding,
                        boolean removeHeader,
                        boolean unicodeLower)

SortedProperties

public SortedProperties(Properties defaults)
Method Detail

keys

public Enumeration<Object> keys()
Overrides:
keys in class Hashtable<Object,Object>

load

public SortedProperties load(File src)
                      throws IOException
Load all properties from given src file using defined defaultEncoding.

Parameters:
src - source file
Returns:
this instance
Throws:
IOException - if any io pb
See Also:
load(File, String)

load

public SortedProperties load(File src,
                             String encoding)
                      throws IOException
Load Properties from src file using given defaultEncoding. If this encoding is different from default ones ENCODING_DEFAULT, ENCODING_LATIN1 and ENCODING_ASCII. A specific Reader will be used to read the file.

Parameters:
src - File where Properties will be loaded
encoding - Encoding to use
Returns:
this instance
Throws:
IOException - for any file errors
Since:
1.3

store

public void store(File dst)
           throws IOException
Save properties in given dst file using defined defaultEncoding.

Parameters:
dst - output file
Throws:
IOException - if any io pb
See Also:
store(File, String)

store

public void store(File dst,
                  String encoding)
           throws IOException
Store Properties in output file using given defaultEncoding. If this encoding is different from default ones ENCODING_DEFAULT, ENCODING_LATIN1 and ENCODING_ASCII, a specific Writer will be used to save the file. Otherwise the default Properties behavior will escape unicode chars with \uxxxx.

Parameters:
dst - File to save Properties
encoding - Encoding to use
Throws:
IOException - for any file errors
Since:
1.3

storeEncode

protected void storeEncode(OutputStream stream,
                           String encoding)
                    throws IOException
If encoding is not the default Properties one, we will use a writer to use this custom encoding.

We must call the right method depends on encoding, for a custom one the store(Writer, String) method is used otherwise the default encoding 8859_1 must be used as superclass define it in store(OutputStream, String).

Encoding ENCODING_DEFAULT, ENCODING_LATIN1 and ENCODING_ASCII are considered as default Properties one, so the old method will be use escaping unicode chars like \uxxxx.

Parameters:
stream - OutputStream to save in
encoding - Encoding to use
Throws:
IOException - For any file errors

store

public void store(OutputStream dst)
           throws IOException
Save properties in given stream file. defaultEncoding defined will be ignored to store the properties file. The default encoding is the basic Properties one (Latin1 ISO), unicode chars will be escaped like basic store(OutputStream, String) method.

Parameters:
dst - output file
Throws:
IOException - if any io pb

store

public void store(OutputStream out,
                  String comments)
           throws IOException
Overrides:
store in class Properties
Throws:
IOException

store

public void store(Writer writer,
                  String comments)
           throws IOException
Overrides:
store in class Properties
Throws:
IOException

store0

protected void store0(BufferedWriter bw,
                      String comments,
                      boolean escUnicode)
               throws IOException
Throws:
IOException

saveConvert

protected String saveConvert(String theString,
                             boolean escapeSpace,
                             boolean escapeUnicode)

writeComments

public void writeComments(BufferedWriter bw,
                          String comments)
                   throws IOException
Throws:
IOException

toHex

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

Parameters:
nibble - the nibble to convert.


Copyright © 2009-2012 CodeLutin. All Rights Reserved.