SourceForge Jpcap

net.sourceforge.jpcap.util
Class PropertyHelper

java.lang.Object
  extended by net.sourceforge.jpcap.util.PropertyHelper

public class PropertyHelper
extends Object

Property helper utility methods.

Version:
$Revision: 1.1 $
Author:
Patrick Charles and Jonas Lehmann, Esmond Pitt
Last modified by:
$Author: esmondpitt $
Last modified at:
$Date: 2008/08/21 02:59:24 $

Constructor Summary
PropertyHelper()
           
 
Method Summary
static boolean getBooleanProperty(Properties properties, Object key)
          Read the specified boolean property.
static Color getColorProperty(Properties properties, Object key)
          Convert a space delimited color tuple string to a color.
static float getFloatProperty(Properties properties, Object key)
          Read the specified float property.
static int getIntProperty(Properties properties, Object key)
          Read the specified integer property.
static int getIpProperty(Properties properties, Object key)
          Convert a dot-delimited IP address to an integer.
static Properties load(String[] paths, String fileName)
          Load the specified properties file from one of the specified set of paths.
static Properties refresh(String name, InputStream in)
          Refresh property settings from an input stream.
 
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(Properties properties,
                                     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(Properties properties,
                                 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 Color getColorProperty(Properties properties,
                                     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(Properties properties,
                                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(Properties properties,
                                         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 Properties refresh(String name,
                                 InputStream in)
                          throws IOException
Refresh property settings from an input stream. Closes the input stream after loading.

Parameters:
name - Property file name
in - Input stream
Throws:
IOException - I/O problem

load

public static Properties load(String[] paths,
                              String fileName)
Load the specified properties file from one of the specified set of paths. The file is looked for both as a class resource and as a filename on the file system.

Parameters:
paths - array of String 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.

Copyright © Patrick Charles & Jonas Lehmann, 2001; Esmond Pitt, 2008.