org.apache.commons.configuration

Class PropertiesConfiguration.PropertiesReader

public static class PropertiesConfiguration.PropertiesReader extends LineNumberReader

This class is used to read properties lines. These lines do not terminate with new-line chars but rather when there is no backslash sign a the end of the line. This is used to concatenate multiple lines for readability.
Field Summary
ListcommentLines
Stores the comment lines for the currently processed property.
chardelimiter
Stores the list delimiter character.
StringpropertyName
Stores the name of the last read property.
StringpropertyValue
Stores the value of the last read property.
Constructor Summary
PropertiesReader(Reader reader)
Constructor.
PropertiesReader(Reader reader, char listDelimiter)
Creates a new instance of PropertiesReader and sets the underlaying reader and the list delimiter.
Method Summary
static booleancheckCombineLines(String line)
Checks if the passed in line should be combined with the following.
ListgetCommentLines()
Returns the comment lines that have been read for the last property.
StringgetPropertyName()
Returns the name of the last read property.
StringgetPropertyValue()
Returns the value of the last read property.
booleannextProperty()
Parses the next property from the input stream and stores the found name and value in internal fields.
static String[]parseProperty(String line)
Parse a property line and return the key and the value in an array.
StringreadProperty()
Reads a property line.

Field Detail

commentLines

private List commentLines
Stores the comment lines for the currently processed property.

delimiter

private char delimiter
Stores the list delimiter character.

propertyName

private String propertyName
Stores the name of the last read property.

propertyValue

private String propertyValue
Stores the value of the last read property.

Constructor Detail

PropertiesReader

public PropertiesReader(Reader reader)
Constructor.

Parameters: reader A Reader.

PropertiesReader

public PropertiesReader(Reader reader, char listDelimiter)
Creates a new instance of PropertiesReader and sets the underlaying reader and the list delimiter.

Parameters: reader the reader listDelimiter the list delimiter character

Since: 1.3

Method Detail

checkCombineLines

private static boolean checkCombineLines(String line)
Checks if the passed in line should be combined with the following. This is true, if the line ends with an odd number of backslashes.

Parameters: line the line

Returns: a flag if the lines should be combined

getCommentLines

public List getCommentLines()
Returns the comment lines that have been read for the last property.

Returns: the comment lines for the last property returned by readProperty()

Since: 1.3

getPropertyName

public String getPropertyName()
Returns the name of the last read property. This method can be called after nextProperty was invoked and its return value was true.

Returns: the name of the last read property

Since: 1.3

getPropertyValue

public String getPropertyValue()
Returns the value of the last read property. This method can be called after nextProperty was invoked and its return value was true.

Returns: the value of the last read property

Since: 1.3

nextProperty

public boolean nextProperty()
Parses the next property from the input stream and stores the found name and value in internal fields. These fields can be obtained using the provided getter methods. The return value indicates whether EOF was reached (false) or whether further properties are available (true).

Returns: a flag if further properties are available

Throws: IOException if an error occurs

Since: 1.3

parseProperty

private static String[] parseProperty(String line)
Parse a property line and return the key and the value in an array.

Parameters: line the line to parse

Returns: an array with the property's key and value

Since: 1.2

readProperty

public String readProperty()
Reads a property line. Returns null if Stream is at EOF. Concatenates lines ending with "\". Skips lines beginning with "#" or "!" and empty lines. The return value is a property definition (<name> = <value>)

Returns: A string containing a property value or null

Throws: IOException in case of an I/O error