org.javaseis.properties
Class SeisProperties

java.lang.Object
  extended by org.javaseis.properties.SeisProperties
All Implemented Interfaces:
java.io.Serializable

public class SeisProperties
extends java.lang.Object
implements java.io.Serializable

Title: JavaSeis Properties

Description: Provides property support for JavaSeis classes

Copyright: Copyright (c) 2003

Company: JavaSeis.com

Version:
1.0
Author:
Chuck Mosher
See Also:
Serialized Form

Field Summary
(package private)  char endChar
           
(package private)  java.nio.channels.FileChannel fc
           
(package private)  java.util.Properties fileProperties
           
(package private)  ISeisLock fl
           
(package private)  java.io.FileOutputStream fo
           
(package private)  java.io.File fpropFile
           
(package private)  java.lang.String header
           
(package private)  long ioTime
           
(package private)  boolean isChanged
           
(package private)  int lockCount
           
(package private)  java.lang.String path
           
(package private)  boolean readOnly
           
(package private)  java.lang.String sepChar
           
(package private)  char startChar
           
(package private)  long t0
           
(package private)  boolean trackTime
           
(package private)  boolean useLocking
           
(package private)  boolean useNativeLock
           
 
Constructor Summary
SeisProperties()
          Create a new JavaSeis properties object
SeisProperties(java.lang.String path, java.lang.String mode)
           
SeisProperties(java.lang.String path, java.lang.String mode, boolean useLocking, boolean nativeLocking)
          Create a file for subsequent JavaSeis properties load/store operations
 
Method Summary
static SeisProperties argsToProperties(java.lang.String[] args)
          Convert a set of program arguments to Properties object Convention used is "-arg1 value1 -arg2 value2" translates to "arg1" = "value1", "arg2 = "value2", etc.
 void broadcast(IParallelContext pc)
          Broadcast properties contents to all tasks in the parallel context
 void clear()
           
 void close()
           
 void create(java.lang.String path, java.lang.String header)
           
 double getDouble(java.lang.String key)
          Get float property value from JavaSeis FileProperties object.
 double getDouble(java.lang.String key, double defaultDouble)
          Get double property value from JavaSeis FileProperties object.
 int getDoubleArray(java.lang.String key, double[] values)
          Get an array of doubles from the JavaSeis FileProperties object.
 int getDoubleArray(java.lang.String key, double[] values, double[] defaults)
          Get an array of doubles from the JavaSeis FileProperties object.
 float getFloat(java.lang.String key)
          Get float property value from JavaSeis FileProperties object.
 float getFloat(java.lang.String key, java.lang.Float defaultFloat)
          Get float property value from JavaSeis FileProperties object.
 int getFloatArray(java.lang.String key, float[] values)
          Get an array of floats from the JavaSeis FileProperties object.
 int getFloatArray(java.lang.String key, float[] values, float[] defaults)
          Get an array of floats from the JavaSeis FileProperties object.
 java.lang.String getHeader()
          Read the "header" line from the properties file
 int getInt(java.lang.String key)
          Get int property value from JavaSeis properties object.
 int getInt(java.lang.String key, int defaultInt)
          Get int property value from JavaSeis properties object.
 int getIntArray(java.lang.String key, int[] values)
          Get an array of integers from the JavaSeis FileProperties object.
 int getIntArray(java.lang.String key, int[] values, int[] defaults)
          Get an array of integers from the JavaSeis FileProperties object.
 float getIoTime()
          Return time spent in I/O operations
 float getLockTime()
          Return time spent in lock operations
 long getLong(java.lang.String key)
          Get long property value from JavaSeis properties object.
 long getLong(java.lang.String key, long defaultLong)
          Get int property value from JavaSeis properties object.
 int getLongArray(java.lang.String key, long[] values)
          Get an array of longs from the JavaSeis FileProperties object.
 int getLongArray(java.lang.String key, long[] values, long[] defaults)
          Get an array of longs from the JavaSeis FileProperties object.
 java.lang.String getPath()
           
 java.lang.String getString(java.lang.String key)
          Get String property value from JavaSeis FileProperties object.
 java.lang.String getString(java.lang.String key, java.lang.String defaultString)
          Get String property value from JavaSeis FileProperties object.
 java.lang.String[] getStringArray(java.lang.String key)
          Retrieve an array of Strings as a property value
 java.lang.String[] getStringArray(java.lang.String key, java.lang.String defaults)
          Retrieve an array of Strings as a property value
 void load()
          Load a JavaSeis properties object from the associated file
 void lock()
          Obtain a lock on the properties file
static java.util.Properties mergeProperties(java.util.Properties oldProps, java.util.Properties newProps, boolean preserve)
          Merges 2 sets of properties.
 void open(java.lang.String path, java.lang.String mode)
          Open properties file
 void open(java.lang.String path, java.lang.String mode, boolean fileLocking, boolean nativeLocking)
          Open a file for subsequent JavaSeis properties load/store operations
 void putDouble(java.lang.String key, double value)
          Store a double value in the JavaSeis FileProperties object.
 void putDoubleArray(java.lang.String key, double[] values)
          Store an array of doubles in the JavaSeis FileProperties object.
 void putFloat(java.lang.String key, float value)
          Store a float value in the JavaSeis FileProperties object.
 void putFloatArray(java.lang.String key, float[] values)
          Store an array of floats in the JavaSeis FileProperties object.
 void putInt(java.lang.String key, int value)
          Store a integer value in the JavaSeis FileProperties object.
 void putIntArray(java.lang.String key, int[] values)
          Store an array of integers in the JavaSeis FileProperties object.
 void putLong(java.lang.String key, long value)
          Store a long value in the JavaSeis FileProperties object.
 void putLongArray(java.lang.String key, long[] values)
          Store an array of longs in the JavaSeis FileProperties object.
 void putString(java.lang.String key, java.lang.String value)
          Store a String property value in the JavaSeis FileProperties object.
 void putStringArray(java.lang.String key, java.lang.String[] values)
          Store an array of Strings as a property value
 void setSeparators(java.lang.String sep, char start, char end)
          Create a file for subsequent JavaSeis properties load/store operations
 void store()
          Store JavaSeis properties to the associated file
static java.lang.String[] stringToArray(java.lang.String s, java.lang.String sep, char start, char end)
          Convert a string to an array of strings based on a separator
 void trackTime(boolean trackTime)
          Set flag for I/O time tracking
 void unlock()
          Release a lock on the properties file
protected  void update(java.lang.String header)
          Updates properties.
 void useLock(boolean lock)
           
 void useNativeLock(boolean useNative)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

endChar

char endChar

fc

java.nio.channels.FileChannel fc

fileProperties

java.util.Properties fileProperties

fl

ISeisLock fl

fo

java.io.FileOutputStream fo

fpropFile

java.io.File fpropFile

header

java.lang.String header

ioTime

long ioTime

isChanged

boolean isChanged

lockCount

int lockCount

path

java.lang.String path

readOnly

boolean readOnly

sepChar

java.lang.String sepChar

startChar

char startChar

t0

long t0

trackTime

boolean trackTime

useLocking

boolean useLocking

useNativeLock

boolean useNativeLock
Constructor Detail

SeisProperties

public SeisProperties()
Create a new JavaSeis properties object


SeisProperties

public SeisProperties(java.lang.String path,
                      java.lang.String mode)
               throws SeisException
Throws:
SeisException

SeisProperties

public SeisProperties(java.lang.String path,
                      java.lang.String mode,
                      boolean useLocking,
                      boolean nativeLocking)
               throws SeisException
Create a file for subsequent JavaSeis properties load/store operations

Parameters:
path - path to use for loading/storing properties
Throws:
SeisException
Method Detail

argsToProperties

public static SeisProperties argsToProperties(java.lang.String[] args)
Convert a set of program arguments to Properties object Convention used is "-arg1 value1 -arg2 value2" translates to "arg1" = "value1", "arg2 = "value2", etc.

Parameters:
args - input program argument strings
Returns:
props output properties

broadcast

public void broadcast(IParallelContext pc)
Broadcast properties contents to all tasks in the parallel context

Parameters:
pc - parallel context to be used for the broadcast

clear

public void clear()

close

public void close()
           throws SeisException
Throws:
SeisException

create

public void create(java.lang.String path,
                   java.lang.String header)
            throws SeisException
Throws:
SeisException

getDouble

public double getDouble(java.lang.String key)
                 throws SeisException
Get float property value from JavaSeis FileProperties object.

Parameters:
key - name of property
Returns:
float value of property matching key
Throws:
SeisException - null property or number format error.

getDouble

public double getDouble(java.lang.String key,
                        double defaultDouble)
Get double property value from JavaSeis FileProperties object.

Parameters:
key - name of property
defaultDouble - default value if matching key is not found
Returns:
double value of property matching key

getDoubleArray

public int getDoubleArray(java.lang.String key,
                          double[] values)
                   throws SeisException
Get an array of doubles from the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be read from the properties file
Returns:
number of elements in the returned array
Throws:
SeisException

getDoubleArray

public int getDoubleArray(java.lang.String key,
                          double[] values,
                          double[] defaults)
Get an array of doubles from the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be read from the properties file
Returns:
number of elements in the returned array
Throws:
SeisException

getFloat

public float getFloat(java.lang.String key)
               throws SeisException
Get float property value from JavaSeis FileProperties object.

Parameters:
key - name of property
Returns:
float value of property matching key
Throws:
SeisException - null property or number format error.

getFloat

public float getFloat(java.lang.String key,
                      java.lang.Float defaultFloat)
Get float property value from JavaSeis FileProperties object.

Parameters:
key - name of property
defaultFloat - default value if property is not found
Returns:
float value of property matching key

getFloatArray

public int getFloatArray(java.lang.String key,
                         float[] values)
                  throws SeisException
Get an array of floats from the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be read from the properties file
Returns:
number of elements in the returned array
Throws:
SeisException

getFloatArray

public int getFloatArray(java.lang.String key,
                         float[] values,
                         float[] defaults)
Get an array of floats from the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be read from the properties file
Returns:
number of elements in the returned array
Throws:
SeisException

getHeader

public java.lang.String getHeader()
                           throws SeisException
Read the "header" line from the properties file

Returns:
String containing header line
Throws:
SeisException - if file cannot be read

getInt

public int getInt(java.lang.String key)
           throws SeisException
Get int property value from JavaSeis properties object.

Parameters:
key - name of property
Returns:
int value of property matching key
Throws:
SeisException - null property or number format error.

getInt

public int getInt(java.lang.String key,
                  int defaultInt)
Get int property value from JavaSeis properties object.

Parameters:
key - name of property
defaultInt - default integer value if matching key not found
Returns:
int value of property matching key

getIntArray

public int getIntArray(java.lang.String key,
                       int[] values)
                throws SeisException
Get an array of integers from the JavaSeis FileProperties object.

Parameters:
key - (in) property to retrieve
values - (out) array of values returned
Returns:
number of elements in the returned array
Throws:
SeisException - if property is missing

getIntArray

public int getIntArray(java.lang.String key,
                       int[] values,
                       int[] defaults)
Get an array of integers from the JavaSeis FileProperties object.

Parameters:
key - (in) property to retrieve
values - (out) array of values returned
Returns:
number of elements in the returned array
Throws:
SeisException - if property is missing

getIoTime

public float getIoTime()
Return time spent in I/O operations

Returns:
time in seconds spent locking the properties file

getLockTime

public float getLockTime()
Return time spent in lock operations

Returns:
time in seconds spent locking the properties file

getLong

public long getLong(java.lang.String key)
             throws SeisException
Get long property value from JavaSeis properties object.

Parameters:
key - name of property
Returns:
long value of property matching key
Throws:
SeisException - null property or number format error.

getLong

public long getLong(java.lang.String key,
                    long defaultLong)
Get int property value from JavaSeis properties object.

Parameters:
key - name of property
defaultInt - default integer value if matching key not found
Returns:
int value of property matching key

getLongArray

public int getLongArray(java.lang.String key,
                        long[] values)
                 throws SeisException
Get an array of longs from the JavaSeis FileProperties object.

Parameters:
key - (in) property to retrieve
values - (out) array of values returned
Returns:
number of elements in the returned array
Throws:
SeisException

getLongArray

public int getLongArray(java.lang.String key,
                        long[] values,
                        long[] defaults)
Get an array of longs from the JavaSeis FileProperties object.

Parameters:
key - (in) property to retrieve
values - (out) array of values returned
Returns:
number of elements in the returned array
Throws:
SeisException

getPath

public java.lang.String getPath()

getString

public java.lang.String getString(java.lang.String key)
                           throws SeisException
Get String property value from JavaSeis FileProperties object.

Parameters:
key - name of property
Returns:
String value of property matching key
Throws:
SeisException - null property or number format error.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultString)
Get String property value from JavaSeis FileProperties object.

Parameters:
key - name of property
Returns:
String value of property matching key

getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Retrieve an array of Strings as a property value

Parameters:
key - string used as key in property file
Returns:
array of strings recovered from properties file

getStringArray

public java.lang.String[] getStringArray(java.lang.String key,
                                         java.lang.String defaults)
Retrieve an array of Strings as a property value

Parameters:
key - string used as key in property file
defaults - default value for string array
Returns:
array of strings recovered from properties file

load

public void load()
          throws SeisException
Load a JavaSeis properties object from the associated file

Throws:
SeisException

lock

public void lock()
          throws SeisException
Obtain a lock on the properties file

Throws:
SeisException - if already locked or lock failure

mergeProperties

public static java.util.Properties mergeProperties(java.util.Properties oldProps,
                                                   java.util.Properties newProps,
                                                   boolean preserve)
                                            throws SeisException
Merges 2 sets of properties.

Parameters:
oldProps - The old set of properties.
newProps - The new set of properties.
preserve - true to preserve old properties; otherwise false.
Returns:
The merged set of properties.
Throws:
SeisException - Thrown on property merge error.

open

public void open(java.lang.String path,
                 java.lang.String mode)
          throws SeisException
Open properties file

Parameters:
path -
mode -
Throws:
SeisException

open

public void open(java.lang.String path,
                 java.lang.String mode,
                 boolean fileLocking,
                 boolean nativeLocking)
          throws SeisException
Open a file for subsequent JavaSeis properties load/store operations

Parameters:
path - path to use for loading/storing properties
mode - "rw" for read/write, "r" for read only
useLocking - flag to indicate whether or not to use locking
nativeLocking - false indicates to use java nio locking
Throws:
SeisException

putDouble

public void putDouble(java.lang.String key,
                      double value)
Store a double value in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
value - string that will be stored in properties file

putDoubleArray

public void putDoubleArray(java.lang.String key,
                           double[] values)
Store an array of doubles in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be stored in properties file

putFloat

public void putFloat(java.lang.String key,
                     float value)
Store a float value in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
value - string that will be stored in properties file

putFloatArray

public void putFloatArray(java.lang.String key,
                          float[] values)
Store an array of floats in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be stored in properties file

putInt

public void putInt(java.lang.String key,
                   int value)
Store a integer value in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
value - string that will be stored in properties file

putIntArray

public void putIntArray(java.lang.String key,
                        int[] values)
Store an array of integers in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be stored in properties file

putLong

public void putLong(java.lang.String key,
                    long value)
Store a long value in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
value - string that will be stored in properties file

putLongArray

public void putLongArray(java.lang.String key,
                         long[] values)
Store an array of longs in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
values - array that will be stored in properties file

putString

public void putString(java.lang.String key,
                      java.lang.String value)
Store a String property value in the JavaSeis FileProperties object.

Parameters:
key - string used as key in property file
value - string that will be stored in properties file

putStringArray

public void putStringArray(java.lang.String key,
                           java.lang.String[] values)
Store an array of Strings as a property value

Parameters:
key - string used as key in property file
values - arrayh of strings that will be stored in properties file

setSeparators

public void setSeparators(java.lang.String sep,
                          char start,
                          char end)
Create a file for subsequent JavaSeis properties load/store operations

Parameters:
path - path to use for loading/storing properties
Throws:
SeisException

store

public void store()
           throws SeisException
Store JavaSeis properties to the associated file

Parameters:
header - string to use in header for properties file
Throws:
SeisException
SeisException

stringToArray

public static java.lang.String[] stringToArray(java.lang.String s,
                                               java.lang.String sep,
                                               char start,
                                               char end)
Convert a string to an array of strings based on a separator

Parameters:
s - input string to be converted to an array
sep - separator between array elements in the string
start - character used to delimit start of string (i.e. ",} )
end - character used to delimit end of string
Returns:
array of strings broken out from the input string

trackTime

public void trackTime(boolean trackTime)
Set flag for I/O time tracking

Parameters:
trackTime - set to true to turn on I/O time tracking

unlock

public void unlock()
            throws SeisException
Release a lock on the properties file

Throws:
SeisException - if not locked or unlock failure

update

protected void update(java.lang.String header)
               throws SeisException
Updates properties. Reloads existing properties, merges current with existing, and then writes back to disk.

Throws:
SeisException - Thrown on property update errors.

useLock

public void useLock(boolean lock)
             throws SeisException
Throws:
SeisException

useNativeLock

public void useNativeLock(boolean useNative)
                   throws SeisException
Throws:
SeisException