ach.file
Class ParamUtil

java.lang.Object
  extended byach.file.ParamUtil

public class ParamUtil
extends java.lang.Object

ParamUtil.java
Copyright (c) 1997-2005 Helge Hackbarth, All Rights Reserved.
Static utilities to retrieve commandline parameters, paths/codebase.

THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.


Field Summary
static java.net.URL codeBase
          codebase of an applet determined at runtime using retrieveCodeBase
static java.net.URL documentBase
           
static java.lang.String progPath
          path to main class file (if run as standalone application) determined at runtime using retrieveProgramPath
 
Constructor Summary
ParamUtil()
           
 
Method Summary
static java.lang.String getFilename(java.awt.Frame parent, java.io.FilenameFilter filenameFilter, java.lang.String nameMasks, java.lang.String initialPath, int mode)
          Get filename using standard FileDialog filenameFilter, masks for filenames and mode (open/save) can be controlled
static byte[] getResourceAsByteArray(java.lang.String resName, java.lang.Class relativeToClass)
          Try to open a resource as stream using Java 1.1 and 1.0 methods path is determined from path of related class if running as applet, ParamUtil.retrieveCodeBase should be run before
static java.util.Hashtable loadProps(java.lang.Object parent)
           
static int netFileToLocalFile(java.net.URL context, java.lang.String name, boolean useGauge)
          Copies a file specified by URL to a local file
static byte[] netFileToRam(java.net.URL context, boolean useGauge)
          Copies a file specified by URL to a byte array
static void retrieveCodeBase(java.applet.Applet parent)
          Retrieve the codebase of an applet (not running standalone).
static java.lang.String[] retrieveParameters(java.lang.String paramStr)
          Separate a parameter string into an array containing single parameters.
static java.lang.String[] retrieveParameters(java.lang.String paramStr, char separator)
          Separate a parameter string into an array containing single parameters.
static void retrieveProgramPath(java.lang.Object mainClass, java.lang.String overridePath)
          For standalone applications we may be interested in the programīs path as the current dir may be changed by file dialogs later.
static void saveProps(java.util.Hashtable props, java.lang.Object parent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

progPath

public static java.lang.String progPath
path to main class file (if run as standalone application) determined at runtime using retrieveProgramPath

See Also:
retrieveProgramPath(java.lang.Object, java.lang.String)

codeBase

public static java.net.URL codeBase
codebase of an applet determined at runtime using retrieveCodeBase

See Also:
retrieveCodeBase(java.applet.Applet)

documentBase

public static java.net.URL documentBase
Constructor Detail

ParamUtil

public ParamUtil()
Method Detail

retrieveParameters

public static java.lang.String[] retrieveParameters(java.lang.String paramStr,
                                                    char separator)
Separate a parameter string into an array containing single parameters. Separated parameters enclosed in qoutes are concatenated together

Parameters:
paramStr - String containing parameters
separator - Character used as separator
Returns:
array of strings

retrieveParameters

public static java.lang.String[] retrieveParameters(java.lang.String paramStr)
Separate a parameter string into an array containing single parameters. Separator char defaulted to blank. Parameters separated with blanks but enclosed in qoutes are kept together

Parameters:
paramStr - String containing parameters (seperatet by blanks)
Returns:
array of strings

retrieveProgramPath

public static void retrieveProgramPath(java.lang.Object mainClass,
                                       java.lang.String overridePath)
For standalone applications we may be interested in the programīs path as the current dir may be changed by file dialogs later. This methods analyzes the CLASSPATH, the parameter overridePath and the current directory. The resulting path is stored in the global static variable progPath


retrieveCodeBase

public static void retrieveCodeBase(java.applet.Applet parent)
Retrieve the codebase of an applet (not running standalone). This might be used later from within classes that are not the main applet class e.g. to load ressources.

Parameters:
parent - the main applet that is running (not standalone)

getResourceAsByteArray

public static byte[] getResourceAsByteArray(java.lang.String resName,
                                            java.lang.Class relativeToClass)
                                     throws java.io.IOException
Try to open a resource as stream using Java 1.1 and 1.0 methods path is determined from path of related class if running as applet, ParamUtil.retrieveCodeBase should be run before

Throws:
java.io.IOException

getFilename

public static java.lang.String getFilename(java.awt.Frame parent,
                                           java.io.FilenameFilter filenameFilter,
                                           java.lang.String nameMasks,
                                           java.lang.String initialPath,
                                           int mode)
                                    throws java.io.IOException
Get filename using standard FileDialog filenameFilter, masks for filenames and mode (open/save) can be controlled

Parameters:
filenameFilter - to filter filenames (see java.io.FilenameFilter) or null
nameMasks - used to mask filenames (e.g. "*.gif, *.jpg")
initialPath - used to set initial path
mode - FileDialog.OPEN or FileDialog.SAVE
Returns:
selected filenam or null, if no filename selected
Throws:
java.io.IOException

netFileToLocalFile

public static int netFileToLocalFile(java.net.URL context,
                                     java.lang.String name,
                                     boolean useGauge)
                              throws java.net.MalformedURLException,
                                     java.io.IOException
Copies a file specified by URL to a local file

Parameters:
context - contains the URL of the file to read
useGauge - to enable or disable a gauge
Returns:
the number of bytes copied
Throws:
java.net.MalformedURLException
java.io.IOException

netFileToRam

public static byte[] netFileToRam(java.net.URL context,
                                  boolean useGauge)
                           throws java.net.MalformedURLException,
                                  java.io.IOException
Copies a file specified by URL to a byte array

Parameters:
context - contains the URL of the file to read
useGauge - to enable or disable a gauge
Returns:
the ByteArray containing the contents of the InputStream
Throws:
java.net.MalformedURLException
java.io.IOException

loadProps

public static java.util.Hashtable loadProps(java.lang.Object parent)

saveProps

public static void saveProps(java.util.Hashtable props,
                             java.lang.Object parent)