APTCONVERT 1.1

fr.pixware.util
Class PlatformUtil

java.lang.Object
  extended by fr.pixware.util.PlatformUtil

public class PlatformUtil
extends java.lang.Object

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


Constructor Summary
PlatformUtil()
           
 
Method Summary
static java.lang.String commandSeparator()
          Returns the command separator of the standard shell of the platform.
static java.lang.String homeDir()
          Returns the name of the home directory of current user.
static java.lang.String platform()
          Returns the name of the platform Java is running on.
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 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlatformUtil

public PlatformUtil()
Method Detail

platform

public static java.lang.String platform()
Returns the name of the platform Java is running on.

Returns:
the name of the platform Java is running on: "windows" or "unix"

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.

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

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

APTCONVERT 1.1