net.sourceforge.jpcap.util
Class PropertyHelper

java.lang.Object
  extended bynet.sourceforge.jpcap.util.PropertyHelper

public class PropertyHelper
extends java.lang.Object

Property helper utility methods.


Constructor Summary
PropertyHelper()
           
 
Method Summary
static boolean getBooleanProperty(java.util.Properties properties, java.lang.Object key)
          Read the specified boolean property.
static java.awt.Color getColorProperty(java.util.Properties properties, java.lang.Object key)
          Convert a space delimited color tuple string to a color.
static float getFloatProperty(java.util.Properties properties, java.lang.Object key)
          Read the specified float property.
static int getIntProperty(java.util.Properties properties, java.lang.Object key)
          Read the specified integer property.
static int getIpProperty(java.util.Properties properties, java.lang.Object key)
          Convert a dot-delimited IP address to an integer.
static java.util.Properties load(java.lang.String[] paths, java.lang.String fileName)
          Load the specified properties file from one of the specified set of paths.
static java.util.Properties refresh(java.lang.String name, java.io.FileInputStream fis)
          Refresh property settings from disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyHelper

public PropertyHelper()
Method Detail

getFloatProperty

public static float getFloatProperty(java.util.Properties properties,
                                     java.lang.Object key)
Read the specified float property.

Throws an exception if the property value isn't a floating-point number.

Parameters:
key - the name of the property
Returns:
the float value of the property

getIntProperty

public static int getIntProperty(java.util.Properties properties,
                                 java.lang.Object key)
Read the specified integer property.

Throws an exception if the property value isn't an integer.

Parameters:
key - the name of the property
Returns:
the integer value of the property

getColorProperty

public static java.awt.Color getColorProperty(java.util.Properties properties,
                                              java.lang.Object key)
Convert a space delimited color tuple string to a color.

Converts a string value like "255 255 0" to a color constant, in this case, yellow.

Parameters:
key - the name of the property
Returns:
a Color object equivalent to the provided string contents. Returns white if the string is null or can't be converted.

getIpProperty

public static int getIpProperty(java.util.Properties properties,
                                java.lang.Object key)
Convert a dot-delimited IP address to an integer.

Converts a string value like "10.0.0.5" to an integer.

Parameters:
key - the name of the property
Returns:
the integer value of the specified IP number. returns zero if the IP number is not valid.

getBooleanProperty

public static boolean getBooleanProperty(java.util.Properties properties,
                                         java.lang.Object key)
Read the specified boolean property. Converts a property value like "true" or "1" to its boolean value.

Returns false if the property doesn't exist or can't be converted to a boolean.

Parameters:
key - the name of the property
Returns:
the property value

refresh

public static java.util.Properties refresh(java.lang.String name,
                                           java.io.FileInputStream fis)
                                    throws java.io.IOException
Refresh property settings from disk.

Throws:
java.io.IOException

load

public static java.util.Properties load(java.lang.String[] paths,
                                        java.lang.String fileName)
Load the specified properties file from one of the specified set of paths.

Parameters:
paths - an array of strings containing target paths.
fileName - the name of the property file.
Returns:
a populated set of properties loaded from the first file found in the set of supplied paths. If no property file is found, returns null.