Qizx/open API

net.axyana.qizxopen.util
Class PlatformUtil

java.lang.Object
  extended bynet.axyana.qizxopen.util.PlatformUtil

public final class PlatformUtil
extends java.lang.Object

A collection of utility functions (static methods) returning information which is platform dependent.


Field Summary
static int GENERIC_UNIX
           
static boolean IS_GENERIC_UNIX
           
static boolean IS_MAC_OS
           
static boolean IS_WINDOWS
           
static int MAC_OS
           
static int PLATFORM
           
static int WINDOWS
           
 
Constructor Summary
PlatformUtil()
           
 
Method Summary
static int captureOutput(java.lang.Process process, java.lang.String[] capture)
          Captures output of specified newly started process (see shellStart(String)).
static java.lang.String commandSeparator()
          Returns the command separator of the standard shell of the platform.
static java.util.HashMap getEnvironment()
          Returns all environment variables in a HashMap.
static void getEnvironment(java.util.HashMap env)
          Adds all environment variables to specified HashMap.
static java.lang.String homeDir()
          Returns the name of the home directory of current user.
static java.lang.String rcFileName(java.lang.String appName)
          Returns the name of the user preference file associated to the specified application.
static int shellExec(java.lang.String command)
          Executes a command using the standard shell of the platform.
static int shellExec(java.lang.String command, boolean verbose)
          Executes a command using the standard shell of the platform.
static int shellExec(java.lang.String command, java.lang.String[] capture)
          Executes a command using the standard shell of the platform, capturing output to System.out and System.err.
static java.lang.Process shellStart(java.lang.String command)
          Executes a command using the standard shell of the platform.
static java.lang.String tmpDir()
          Returns the name of directory where temporary files can be created safely.
static java.lang.String tmpFileName()
          Returns the name of a temporary file ending with extension ".tmp".
static java.lang.String tmpFileName(java.lang.String extension)
          Returns the name of a temporary file ending with the specified extension.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERIC_UNIX

public static final int GENERIC_UNIX
See Also:
Constant Field Values

WINDOWS

public static final int WINDOWS
See Also:
Constant Field Values

MAC_OS

public static final int MAC_OS
See Also:
Constant Field Values

PLATFORM

public static final int PLATFORM

IS_GENERIC_UNIX

public static final boolean IS_GENERIC_UNIX

IS_WINDOWS

public static final boolean IS_WINDOWS

IS_MAC_OS

public static final boolean IS_MAC_OS
Constructor Detail

PlatformUtil

public PlatformUtil()
Method Detail

homeDir

public static java.lang.String homeDir()
Returns the name of the home directory of current user. The system property HOME, if set to an existing directory name, may be used to force the value returned by this function.

Returns:
the name of the home directory of current user or null if the candidate directory found by this function does not exist or is not a directory.

rcFileName

public static java.lang.String rcFileName(java.lang.String appName)
Returns the name of the user preference file associated to the specified application.

Note that RC means Runtime Configuration.

Parameters:
appName - the application name
Returns:
the name of the user preference file or null if the user HOME directory is unknown
See Also:
homeDir()

tmpFileName

public static java.lang.String tmpFileName()
Returns the name of a temporary file ending with extension ".tmp". The directory of this file is the directory returned by tmpDir().

Returns:
the name of a temporary file

tmpFileName

public static java.lang.String tmpFileName(java.lang.String extension)
Returns the name of a temporary file ending with the specified extension. The directory of this file is the directory returned by tmpDir().

Parameters:
extension - the desired extension for the file name; if a dot is required, add it at the start of extension
Returns:
the name of a temporary file

tmpDir

public static java.lang.String tmpDir()
Returns the name of directory where temporary files can be created safely.

Under Windows, the system property TMP or TEMP, if set to an existing directory, may be used to force the value returned by this function.

Under Unix, this function always returns "/tmp".

Returns:
the name of the temporary directory or null if the candidate directory found by this function does not exist or is not a directory.

commandSeparator

public static java.lang.String commandSeparator()
Returns the command separator of the standard shell of the platform. Example: it is ';' for the bourne shell /bin/sh of Unix.

Returns:
the command separator of the standard shell of the platform

shellStart

public static java.lang.Process shellStart(java.lang.String command)
                                    throws java.io.IOException
Executes a command using the standard shell of the platform. Unlike shellExec(String), does not wait until the command is completed.

Parameters:
command - the shell command to be executed
Returns:
the process of the shell
Throws:
java.io.IOException - if an I/O error occurs

shellExec

public static int shellExec(java.lang.String command)
                     throws java.io.IOException,
                            java.lang.InterruptedException
Executes a command using the standard shell of the platform.

Parameters:
command - the shell command to be executed
Returns:
the exit status returned by the shell
Throws:
java.io.IOException - if an I/O error occurs
java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting the completion of the shell command

shellExec

public static int shellExec(java.lang.String command,
                            boolean verbose)
                     throws java.io.IOException,
                            java.lang.InterruptedException
Executes a command using the standard shell of the platform.

Parameters:
command - the shell command to be executed
verbose - if true, the shell command output on System.out and System.err is echoed; if false, this output is discarded
Returns:
the exit status returned by the shell
Throws:
java.io.IOException - if an I/O error occurs
java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting the completion of the shell command

shellExec

public static int shellExec(java.lang.String command,
                            java.lang.String[] capture)
                     throws java.io.IOException,
                            java.lang.InterruptedException
Executes a command using the standard shell of the platform, capturing output to System.out and System.err.

Parameters:
command - the shell command to be executed
capture - output to System.out is captured and saved to capture[0] and output to System.err is captured and saved to capture[1].
Returns:
the exit status returned by the shell
Throws:
java.io.IOException - if an I/O error occurs
java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting the completion of the shell command

captureOutput

public static int captureOutput(java.lang.Process process,
                                java.lang.String[] capture)
                         throws java.lang.InterruptedException
Captures output of specified newly started process (see shellStart(String)).

Parameters:
process - newly started process
capture - output to System.out is captured and saved to capture[0] and output to System.err is captured and saved to capture[1].
Returns:
exit status of process
Throws:
java.lang.InterruptedException - if the current thread is interrupted by another thread while it is waiting the completion of the process

getEnvironment

public static java.util.HashMap getEnvironment()
Returns all environment variables in a HashMap.

entrySet().iterator() can be used to enumerate Map.Entry where the key is (case-sensitive) name of the environment variable and the value is the value of the environment variable.


getEnvironment

public static void getEnvironment(java.util.HashMap env)
Adds all environment variables to specified HashMap.

entrySet().iterator() can be used to enumerate Map.Entry where the key is (case-sensitive) name of the environment variable and the value is the value of the environment variable.


© 2005 Axyana Software