CXI
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CryptoServerConfig Class Reference

This class provides methods to read and parse configuration files and access configuration items. More...

Public Member Functions

 CryptoServerConfig (InputStream configStream) throws IOException
 Creates a CryptoServerConfig object from the given configuration stream. More...
 
 CryptoServerConfig (String fileName) throws IOException
 Creates a CryptoServerConfig object from the given configuration file. More...
 
boolean exist (String key)
 Checks the existance of the given configuration item. More...
 
byte[] getValue (String key, byte[] def)
 Returns the desired configuration value or a default value if the configuration item doesn't exist. More...
 
int getInt (String key, int def) throws NumberFormatException
 Returns the desired configuration value or a default value if the configuration item doesn't exist. More...
 
boolean getBoolean (String key, boolean def) throws NumberFormatException
 Returns the desired configuration value or a default value if the configuration item doesn't exist. More...
 
String getString (String key, String def)
 Returns the desired configuration value or a default value if the configuration item doesn't exist. More...
 
String[] getStringValues (String key, String[] def)
 Returns an array of configuration values. More...
 
void add (String key, String value)
 Adds a configuration item to the configuration object. More...
 

Detailed Description

This class provides methods to read and parse configuration files and access configuration items.

Each line in a configuration file contains a keyword and one or more values.
Valid lines have to be structured according the scheme:

<KEY> = <VALUE>

Optionally multiple values can be assigned to a key either separated by a space or tabulator:

<KEY> = <VALUE1> <VALUE2> <VALUE3>

or spread over multiple lines each ended by a backslash:

<KEY> = <VALUE1> \
<VALUE2> \
<VALUE3>
Note
Internally java.util.Properties is used to load and parse the configuration file.
Example:
CryptoServerConfig config = new CryptoServerConfig(./my.config");
// retrieve integer value
int iValue = config.getInt("Counter", 0);
// retrieve single string
String label = config.getString("Label", null);
// retrieve boolean value
boolean switch = config.getBoolean("Switch", true);
This class provides methods to read and parse configuration files and access configuration items.
Definition: CryptoServerConfig.java:64

A sample configuration file looks like this:

# Sample configuration file
LogFile = C:/temp/CryptoServer.log
LogLevel = 2
LogSize = 1MB
# cluster
Device = PCI:0 \
192.168.4.1 192.168.4.2
# timeout on connection establishment
ConnectionTimeout = 3000
# command (read) timeout in milliseconds
Timeout = 60000

Constructor & Destructor Documentation

◆ CryptoServerConfig() [1/2]

CryptoServerConfig ( InputStream  configStream) throws IOException

Creates a CryptoServerConfig object from the given configuration stream.

Parameters
configStreamStream to read configuration.

◆ CryptoServerConfig() [2/2]

CryptoServerConfig ( String  fileName) throws IOException

Creates a CryptoServerConfig object from the given configuration file.

Parameters
fileNameName of the configuration file including its path.

Member Function Documentation

◆ exist()

boolean exist ( String  key)

Checks the existance of the given configuration item.

Parameters
keyKeyword to be checked

◆ getValue()

byte[] getValue ( String  key,
byte[]  def 
)

Returns the desired configuration value or a default value if the configuration item doesn't exist.

Parameters
keyConfiguration item to be retrieved
defDefault value that is returned if the desired item doesn't exist

◆ getInt()

int getInt ( String  key,
int  def 
) throws NumberFormatException

Returns the desired configuration value or a default value if the configuration item doesn't exist.

Parameters
keyConfiguration item to be retrieved.
defDefault value that is returned if the desired item doesn't exist.

◆ getBoolean()

boolean getBoolean ( String  key,
boolean  def 
) throws NumberFormatException

Returns the desired configuration value or a default value if the configuration item doesn't exist.


The values 'true', 'y' or '1' are interpreted as true. The values 'false', 'n' or '0' are interpreted as false.

Parameters
keyConfiguration item to be retrieved.
defDefault value that is returned if the desired item doesn't exist.

◆ getString()

String getString ( String  key,
String  def 
)

Returns the desired configuration value or a default value if the configuration item doesn't exist.

Parameters
keyConfiguration item to be retrieved
defDefault value that is returned if the desired item doesn't exist

◆ getStringValues()

String[] getStringValues ( String  key,
String[]  def 
)

Returns an array of configuration values.

Multiple configuration items have to be separated by one or more blanks and may span across multiple lines, each ended by a backslash character.

Parameters
keyConfiguration item to be retrieved.
defDefault value that is returned if the desired item doesn't exist.

◆ add()

void add ( String  key,
String  value 
)

Adds a configuration item to the configuration object.

Parameters
keyKeyword name of the configuration item to be added.
valueConfiguration value corresponding to key.