org.pz.platypus
Class PropertyFile
java.lang.Object
org.pz.platypus.PropertyFile
- Direct Known Subclasses:
- Literals
public class PropertyFile
- extends java.lang.Object
Reads a properties file and parses it into a Map. The Java library
has routines for doing this, but they have some constraints, such as naming, that
are not found here.
- Author:
- alb
Field Summary |
private java.util.HashMap<java.lang.String,java.lang.String> |
contents
the Map of key value pairs taken from the property file |
private java.lang.String |
filename
the filename of the property file |
protected GDD |
gdd
|
Constructor Summary |
PropertyFile()
This constructor is used only when extending PropertyFile
for testing purposes. |
PropertyFile(java.lang.String propertyFilename,
GDD Gdd)
|
Method Summary |
java.util.Map<java.lang.String,java.lang.String> |
getContents()
|
int |
getSize()
|
java.util.Set<java.lang.String> |
keySet()
|
int |
load()
read the file into a map. |
void |
loadLine(java.lang.String line)
Find the lines with properties; break them into key-value pairs, load them into hash map |
java.lang.String |
lookup(java.lang.String key)
Look up a property based on a search key |
java.io.BufferedReader |
open(java.lang.String fileName)
open the property file |
java.lang.String |
retrieveNextLine(java.io.BufferedReader reader)
Reads the next line, strips out comments, and trims any whitespace at end of line. |
void |
setFilename(java.lang.String newFilename)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
filename
private java.lang.String filename
- the filename of the property file
contents
private final java.util.HashMap<java.lang.String,java.lang.String> contents
- the Map of key value pairs taken from the property file
gdd
protected final GDD gdd
PropertyFile
public PropertyFile(java.lang.String propertyFilename,
GDD Gdd)
PropertyFile
public PropertyFile()
- This constructor is used only when extending PropertyFile
for testing purposes.
load
public int load()
- read the file into a map. Involves reading the file, trimming the entries, removing the
comments, and splitting the lines into key,value pairs at the first = sign
- Returns:
- Status.OK, if all went well; else Status.IO_ERR
retrieveNextLine
public java.lang.String retrieveNextLine(java.io.BufferedReader reader)
- Reads the next line, strips out comments, and trims any whitespace at end of line.
- Parameters:
reader
- the input reader for the file
- Returns:
- the line, "" if the line is a comment or empty, null at EOF or if an error occurred.
loadLine
public void loadLine(java.lang.String line)
- Find the lines with properties; break them into key-value pairs, load them into hash map
- Parameters:
line
- input lines from the property file
open
public java.io.BufferedReader open(java.lang.String fileName)
- open the property file
- Parameters:
fileName
- name of the file to open
- Returns:
- the buffered reader, if all went well; otherwise, null.
lookup
public java.lang.String lookup(java.lang.String key)
- Look up a property based on a search key
- Parameters:
key
- the key used to look up the property
- Returns:
- the property if found; otherwise, null
getContents
public java.util.Map<java.lang.String,java.lang.String> getContents()
setFilename
public void setFilename(java.lang.String newFilename)
keySet
public java.util.Set<java.lang.String> keySet()
getSize
public int getSize()
Copyright © 2008-10 Pacific Data Works LLC