com.tuneology.avm
Class Native

java.lang.Object
  |
  +--com.tuneology.avm.Native

public class Native
extends java.lang.Object

This class extends the System and Runtime classes to provide extra functionality.

Version:
$Id: Native.java,v 1.17 2003/07/10 19:52:12 xnarf Exp $
Author:
Fran Taylor

Inner Class Summary
static interface Native.LineReader
          This class gets called for each line of output generated by the program.
static interface Native.Logger
          This class is called for each line of output generated by a shell program.
 
Field Summary
static java.lang.String distName
          For linux, contains the name and version of the distribution.
static boolean isLinux
          True if the jvm is running on Linux.
static boolean isOSX
          True if the jvm is running on OS X.
static boolean isSolaris
          True if the jvm is running on Solaris.
static boolean isWindows
          True if the jvm is running on some sort of Windows.
static java.lang.String version
          Contains the version information for java-avm.
 
Method Summary
static void addEnv(java.lang.String key, java.lang.String val)
          Adds the string to the value of the environment variable.
static java.lang.Process exec(java.util.ArrayList v)
           
static java.lang.Process exec(java.lang.String[] cmd)
           
static java.lang.String getArgString(java.util.ArrayList cmd)
          Returns the list of arguments quoted in a single string, for logging purposes.
static java.lang.String getArgString(java.lang.String[] cmd)
          Returns the list of arguments quoted in a single string, for logging purposes.
static java.util.ArrayList getMkfifoCmd()
          Returns the mkfifo command.
static int getpid()
           
static java.io.File getPreferredTempDirectory()
          Returns the directory for storing temp files.
static java.io.File getPrefsDirectory()
          Returns the directory for storing preferences files.
static java.net.URL getResource(java.lang.String key)
           
static java.lang.String getResourceString(java.lang.String str)
          Returns a string from the resource bundle.
static java.lang.String[] getStringArray(java.util.ArrayList v)
          Takes a vector of strings and creates an array of strings.
static java.io.File getTrashDirectory()
          Return the trash directory.
static boolean isExecutable(java.lang.String path)
          Returns true if the pathname specifies an executable program.
static void mkfifo(java.io.File f)
          For Unix only: executes the mkfifo command.
static void openBrowserWindow(java.lang.String url)
           
static java.util.ArrayList parseUserInput(java.lang.String str)
          Parses the user input and returns it in the form of a vector of strings, ready to pass to runCommand.
static void registerApplListener(ApplListener listener)
           
static void removeApplListener(ApplListener listener)
           
static int runCommand(java.util.ArrayList v, java.io.File dir, java.lang.String enc, Native.LineReader lrdr, boolean logOutput)
          Runs the specified external program.
static int runCommand(java.lang.String[] cmd, java.io.File dir, java.lang.String enc, Native.LineReader lrdr, boolean logOutput)
          Runs the specified external program.
static int runCommand(java.lang.String cmd, java.io.File dir, java.lang.String enc, Native.LineReader lrdr, boolean logOutput)
          Runs the specified external program.
static void setLibraryPath(java.lang.String libPath)
          Adds this directory to the directories searched for libraries by subprocesses.
static void setLogger(Native.Logger l)
          All process I/O is logged to this interface.
static void setMkfifoCmd(java.lang.String s)
          Sets the shell command used for mkfifo.
static void touch()
           
static java.lang.Class tryPlugin(java.lang.String className, java.net.URL[] urls)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isWindows

public static final boolean isWindows
True if the jvm is running on some sort of Windows.

isLinux

public static final boolean isLinux
True if the jvm is running on Linux.

isSolaris

public static final boolean isSolaris
True if the jvm is running on Solaris.

isOSX

public static final boolean isOSX
True if the jvm is running on OS X.

distName

public static final java.lang.String distName
For linux, contains the name and version of the distribution.

version

public static final java.lang.String version
Contains the version information for java-avm.
Method Detail

getArgString

public static java.lang.String getArgString(java.lang.String[] cmd)
Returns the list of arguments quoted in a single string, for logging purposes.
Parameters:
cmd - the argument array.
Returns:
the quoted list of arguments as a single string.

getArgString

public static java.lang.String getArgString(java.util.ArrayList cmd)
Returns the list of arguments quoted in a single string, for logging purposes.
Parameters:
cmd - the String arguments.
Returns:
the quoted list of arguments as a single string.

parseUserInput

public static java.util.ArrayList parseUserInput(java.lang.String str)
Parses the user input and returns it in the form of a vector of strings, ready to pass to runCommand. Values within double quotes are preserved as is otherwise, spaces delimit args.
Parameters:
str - The string to be parsed.
Returns:
a vector containing string arguments.

getpid

public static int getpid()

exec

public static java.lang.Process exec(java.util.ArrayList v)
                              throws java.io.IOException
Throws:
java.io.IOException -  

exec

public static java.lang.Process exec(java.lang.String[] cmd)
                              throws java.io.IOException
Throws:
java.io.IOException -  

runCommand

public static int runCommand(java.lang.String cmd,
                             java.io.File dir,
                             java.lang.String enc,
                             Native.LineReader lrdr,
                             boolean logOutput)
                      throws java.lang.Exception
Runs the specified external program. Blocks until the program exits.
Parameters:
cmd - the shell command to run
dir - the directory in which to run it, or null for the current directory.
enc - the character encoding to use in reading the process output, or null for the default.
lrdr - the line reader used to parse the user input (optional).
logOutput - true if the process's output is to be logged, false if its output is not to be logged.
Returns:
The value returned by the process.
Throws:
java.lang.Exception - if an error occurs

runCommand

public static int runCommand(java.util.ArrayList v,
                             java.io.File dir,
                             java.lang.String enc,
                             Native.LineReader lrdr,
                             boolean logOutput)
                      throws java.lang.Exception
Runs the specified external program. Blocks until the program exits.
Parameters:
v - The shell command to run, as a vector of strings.
dir - the directory in which to run it, or null for the current directory.
enc - the character encoding to use in reading the process output, or null for the default.
lrdr - the line reader used to parse the user input (optional).
logOutput - true if the process's output is to be logged, false if its output is not to be logged.
Returns:
The value returned by the process.
Throws:
java.lang.Exception - if an error occurs

runCommand

public static int runCommand(java.lang.String[] cmd,
                             java.io.File dir,
                             java.lang.String enc,
                             Native.LineReader lrdr,
                             boolean logOutput)
                      throws java.lang.Exception
Runs the specified external program. Blocks until the program exits.
Parameters:
cmd - The shell command to run, as an array of strings.
dir - the directory in which to run it, or null for the current directory.
enc - the character encoding to use in reading the process output, or null for the default.
lrdr - the line reader used to parse the user input (optional).
logOutput - true if the process's output is to be logged, false if its output is not to be logged.
Returns:
The value returned by the process.
Throws:
java.lang.Exception - if an error occurs

getStringArray

public static java.lang.String[] getStringArray(java.util.ArrayList v)
Takes a vector of strings and creates an array of strings.
Parameters:
v - A vector containing strings.
Returns:
An array made of the strings in the vector.

mkfifo

public static void mkfifo(java.io.File f)
                   throws java.lang.Exception
For Unix only: executes the mkfifo command.
Parameters:
f - the file pointing to the fifo to be created.
Throws:
java.lang.Exception - If there was an error executing the mkfifo command.

isExecutable

public static boolean isExecutable(java.lang.String path)
Returns true if the pathname specifies an executable program.
Parameters:
path - A pathname.
Returns:
true if the path is an executable file.

setMkfifoCmd

public static void setMkfifoCmd(java.lang.String s)
                         throws java.io.IOException
Sets the shell command used for mkfifo.
Parameters:
s - the mkfifo command.

setLogger

public static void setLogger(Native.Logger l)
All process I/O is logged to this interface.
Parameters:
l - the logger object.

getResourceString

public static java.lang.String getResourceString(java.lang.String str)
Returns a string from the resource bundle.
Parameters:
str - the identifier for the string.
Returns:
the resource string.

getResource

public static java.net.URL getResource(java.lang.String key)

getMkfifoCmd

public static java.util.ArrayList getMkfifoCmd()
Returns the mkfifo command.
Returns:
the mkfifo command.

getPreferredTempDirectory

public static java.io.File getPreferredTempDirectory()
                                              throws java.io.FileNotFoundException
Returns the directory for storing temp files.
Returns:
the directory for storing temp files
Throws:
java.io.FileNotFoundException -  

getPrefsDirectory

public static java.io.File getPrefsDirectory()
                                      throws java.io.FileNotFoundException
Returns the directory for storing preferences files.
Returns:
the directory for storing preferences files
Throws:
java.io.FileNotFoundException -  

getTrashDirectory

public static java.io.File getTrashDirectory()
                                      throws java.io.FileNotFoundException
Return the trash directory.
Returns:
the trash directory.
Throws:
java.io.FileNotFoundException -  

setLibraryPath

public static void setLibraryPath(java.lang.String libPath)
Adds this directory to the directories searched for libraries by subprocesses.
Parameters:
libPath -  

addEnv

public static void addEnv(java.lang.String key,
                          java.lang.String val)
Adds the string to the value of the environment variable.
Parameters:
key -  
val -  

openBrowserWindow

public static void openBrowserWindow(java.lang.String url)
                              throws java.io.IOException,
                                     java.lang.UnsupportedOperationException
Parameters:
url -  
Throws:
java.io.IOException -  

registerApplListener

public static void registerApplListener(ApplListener listener)
Parameters:
listener -  

removeApplListener

public static void removeApplListener(ApplListener listener)
Parameters:
listener -  

touch

public static void touch()

tryPlugin

public static java.lang.Class tryPlugin(java.lang.String className,
                                        java.net.URL[] urls)
                                 throws java.lang.Throwable