org.af.commons.tools
Class OSTools

java.lang.Object
  extended by org.af.commons.tools.OSTools

public class OSTools
extends Object

The Class OSToolsLocal owns static methods to determine the Operating System and to set up an OS-dependent environment.


Constructor Summary
OSTools()
           
 
Method Summary
static String getBash()
           
static String getTempDir()
          Returns system temporary directory.
static File guessDesktop()
           
static String guessPDFViewerOptions(String pdfviewerpath)
          Guesses Options necessary for PDF viewer.
static String guessPDFViewerPath()
          Guesses absolute path to PDF viewer.
static boolean isLinux()
          Checks whether OS is Linux by parsing the System property os.name.
static boolean isMac()
           
static boolean isUnix()
           
static boolean isVista()
          Checks whether OS is Vista by parsing the System property os.name.
static boolean isWindows()
          In case of doubt we assume Windows to be our OS.
static void makeShellScript(File target, List<String> commands)
           
static Process runShellScript(File script, File workingDir)
           
static Process runShellScript(File script, File workingDir, List<String> inputStreamLines)
          Runs a script.
static int runShellScript(File script, File workingDir, List<String> inputStreamLines, List<String> outputStreamLines)
          Runs a script.
static String searchDir(String[] search, String[] searchDir, String[] searchFile, boolean directory)
          Searches for files and returns the first candidate.
static String searchforFile(File dir, String[] searchDir, String[] searchFile, boolean directory)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OSTools

public OSTools()
Method Detail

isVista

public static boolean isVista()
Checks whether OS is Vista by parsing the System property os.name.

Returns:
is OS Vista?

isLinux

public static boolean isLinux()
Checks whether OS is Linux by parsing the System property os.name.

Returns:
is OS Linux?

isMac

public static boolean isMac()

isUnix

public static boolean isUnix()

isWindows

public static boolean isWindows()
In case of doubt we assume Windows to be our OS. Since up to now only Linux, Mac and Windows are supported isWindows() just returns !isLinux() && !isMac().

Returns:
is OS Windows?

makeShellScript

public static void makeShellScript(File target,
                                   List<String> commands)
                            throws FileNotFoundException,
                                   UnsupportedEncodingException
Throws:
FileNotFoundException
UnsupportedEncodingException

runShellScript

public static Process runShellScript(File script,
                                     File workingDir)
                              throws IOException
Throws:
IOException

getBash

public static String getBash()

runShellScript

public static Process runShellScript(File script,
                                     File workingDir,
                                     List<String> inputStreamLines)
                              throws IOException
Runs a script. On a windows box it is executed via cmd /c, on a Unix system via a bash.

Parameters:
script -
workingDir -
inputStreamLines -
Returns:
the Process that runs this script
Throws:
IOException

runShellScript

public static int runShellScript(File script,
                                 File workingDir,
                                 List<String> inputStreamLines,
                                 List<String> outputStreamLines)
                          throws IOException,
                                 InterruptedException
Runs a script. On a windows box it is executed via cmd /c, on a Unix system via a bash.

Parameters:
script - script to execute
workingDir -
inputStreamLines -
outputStreamLines -
Returns:
The exit code of the Process. Note that each line of the output is added to outputStreamLines.
Throws:
IOException
InterruptedException

guessDesktop

public static File guessDesktop()

guessPDFViewerPath

public static String guessPDFViewerPath()
Guesses absolute path to PDF viewer.

Returns:
Guessed path to PDF viewer.

searchDir

public static String searchDir(String[] search,
                               String[] searchDir,
                               String[] searchFile,
                               boolean directory)
Searches for files and returns the first candidate.

Parameters:
search - Array of paths to the root directories of this search.
searchDir - Files which contain these Strings as substrings should be searched.
searchFile - Files which contain these Strings as substrings are final candidates.
directory - is the file we are looking for a directory?
Returns:
first directory that meet the demands

searchforFile

public static String searchforFile(File dir,
                                   String[] searchDir,
                                   String[] searchFile,
                                   boolean directory)

guessPDFViewerOptions

public static String guessPDFViewerOptions(String pdfviewerpath)
Guesses Options necessary for PDF viewer. So far: Windows + Acrobat : /s /o

Parameters:
pdfviewerpath - Absolute path to PDF viewer.
Returns:
PDF-Viewer-Options

getTempDir

public static String getTempDir()
Returns system temporary directory.

Returns:
Guessed path to R Home.