org.pf.file
Class PropertyFileLoader

java.lang.Object
  extended by org.pf.file.PropertyFileLoader
All Implemented Interfaces:
LineProcessor

public class PropertyFileLoader
extends java.lang.Object
implements LineProcessor

Provides some static convenience methods to load properties from property files. The files will be searched on the classpath. They will be properly loaded even from files inside archives.

Version:
1.6
Author:
Manfred Duchrow

Method Summary
static PropertiesFileContent loadFullPropertiesFile(java.io.InputStream stream)
          Reads all text lines from the given stream and returns the result in an PropertiesFileContent object.
static PropertiesFileContent loadFullPropertiesFile(java.io.Reader reader)
          Reads all text lines from the given stream and returns the result in an PropertiesFileContent object.
static PropertiesFileContent loadFullPropertiesFile(java.lang.String filename)
          Reads all text lines from the given file and returns the result in an PropertiesFileContent object.
static java.util.Properties loadProperties(java.io.File file)
          Loads all properties from the given file.
static java.util.Properties loadProperties(FileLocator locator)
          Loads all properties from the specified file.
static java.util.Properties loadProperties(FileLocator locator, java.util.Properties defaults)
          Load all properties from the given file.
static java.util.Properties loadProperties(java.io.File file, java.util.Properties defaults)
          Load all properties from the given file.
static java.util.Properties loadProperties(java.io.InputStream stream)
          Loads all properties from the given stream.
static java.util.Properties loadProperties(java.io.InputStream stream, java.util.Properties defaults)
          Loads all properties from the given stream.
static java.util.Properties loadProperties(java.lang.String filename)
          Loads all properties from the file with the given name.
static java.util.Properties loadProperties(java.lang.String filename, java.util.Properties defaults)
          Loads all properties from the file with the given name.
static java.util.Properties loadProperties(java.net.URL url, java.util.Properties defaults)
          Load all properties from the file specified by the given URL.
 boolean processLine(java.lang.String line, int lineNo)
          Processes each line that is read from the file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadProperties

public static java.util.Properties loadProperties(java.lang.String filename)
Loads all properties from the file with the given name. Returns the properties or null in any case of exception or if the file wasn't found.


loadProperties

public static java.util.Properties loadProperties(java.lang.String filename,
                                                  java.util.Properties defaults)
Loads all properties from the file with the given name. Returns the properties or null in any case of exception or if the file wasn't found. Places the given default properties into the newly created properties as defaults.


loadProperties

public static java.util.Properties loadProperties(java.io.File file)
Loads all properties from the given file. Returns the properties or null in any case of exception or if the file wasn't found.


loadProperties

public static java.util.Properties loadProperties(java.io.File file,
                                                  java.util.Properties defaults)
Load all properties from the given file. Returns the properties or null in any case of exception or if the file wasn't found. The given default properties a used as default values, if the corresponding properties are not set in the file.


loadProperties

public static java.util.Properties loadProperties(FileLocator locator)
Loads all properties from the specified file. Returns the properties or null in any case of exception or if the file wasn't found.


loadProperties

public static java.util.Properties loadProperties(FileLocator locator,
                                                  java.util.Properties defaults)
Load all properties from the given file. Returns the properties or null in any case of exception or if the file wasn't found. The given default properties a used as default values, if the corresponding properties are not set in the file.


loadProperties

public static java.util.Properties loadProperties(java.net.URL url,
                                                  java.util.Properties defaults)
Load all properties from the file specified by the given URL. Returns the properties or null in any case of exception or if the file wasn't found. The given default properties a used as default values, if the corresponding properties are not set in the file.

Parameters:
url - The url that specifies the file to read the properties from
defaults - The default properties to be put into the result (may be null)

loadProperties

public static java.util.Properties loadProperties(java.io.InputStream stream,
                                                  java.util.Properties defaults)
                                           throws java.io.IOException
Loads all properties from the given stream. Returns the properties. If the given default properties are not null they are set as defaults in the newly created properties object.

Parameters:
stream - The stream to read the properties from
defaults - The default properties (might be null)
Throws:
java.io.IOException

loadProperties

public static java.util.Properties loadProperties(java.io.InputStream stream)
                                           throws java.io.IOException
Loads all properties from the given stream. Returns the properties.

Parameters:
stream - The stream to read the properties from
Throws:
java.io.IOException

loadFullPropertiesFile

public static PropertiesFileContent loadFullPropertiesFile(java.lang.String filename)
                                                    throws java.io.IOException
Reads all text lines from the given file and returns the result in an PropertiesFileContent object. All comments and blank lines are preserved. The order of the properties will be the same as in the file. Apart from that the backslash is not treated as a special character for escaping character sequences. That means, all single backslashes in the file will be preserved as well.

Parameters:
filename - The name of the file to read (can be also a URL)
Throws:
java.io.IOException

loadFullPropertiesFile

public static PropertiesFileContent loadFullPropertiesFile(java.io.Reader reader)
                                                    throws java.io.IOException
Reads all text lines from the given stream and returns the result in an PropertiesFileContent object. All comments and blank lines are preserved. The order of the properties will be the same as in the file. Apart from that the backslash is not treated as a special character for escaping character sequences. That means, all single backslashes in the file will be preserved as well. Using a reader even allows to read properties from sources that have a different character encoding than the default. After the calling this method the given reader will be closed!

Parameters:
reader - The reader to load the data from
Throws:
java.io.IOException

loadFullPropertiesFile

public static PropertiesFileContent loadFullPropertiesFile(java.io.InputStream stream)
                                                    throws java.io.IOException
Reads all text lines from the given stream and returns the result in an PropertiesFileContent object. All comments and blank lines are preserved. The order of the properties will be the same as in the file. Apart from that the backslash is not treated as a special character for escaping character sequences. That means, all single backslashes in the file will be preserved as well. After the calling this method the given stream will be closed!

Parameters:
stream - The stream to read the data from
Throws:
java.io.IOException

processLine

public boolean processLine(java.lang.String line,
                           int lineNo)
Processes each line that is read from the file

Specified by:
processLine in interface LineProcessor
Parameters:
line - The line to process (must not be null)
lineNo - The linen number (starting with 1)