com.muchsoft.util
Class Sys

java.lang.Object
  extended bycom.muchsoft.util.Sys

public class Sys
extends java.lang.Object

This class lets you determine which system your Java application runs on. Furthermore, it offers methods for cross-platform queries for certain paths such as the preferences folder. It is used as follows:

 if (Sys.isMacOSX())
 {
   // Mac OS X-specific code goes here...
 }
 else
 {
   // code for other systems
 }
 
 // store user's configuration data
 DataOutputStream out = new DataOutputStream(
                          new BufferedOutputStream(
                            new FileOutputStream(
                              new File( Sys.getPrefsDirectory(), "config.dat" )
                        )));
 //...

The latest Sys version can be found at http://www.muchsoft.com/java/.

Copyright 1998-2004 by Thomas Much, thomas@muchsoft.com.
This class is free for commercial and non-commercial use, as long as you do not distribute modified versions of the source code. If you have any suggestions, bug reports or feature requests, let me know.

Version History:

2004-10-13
Added a new package, com.muchsoft.util.mac, and a new class, Mac.
2004-05-04
isMacOSX() now matches http://developer.apple.com/technotes/tn2002/tn2110.html
2003-12-02
First public release.

Version:
2004-10-13
Author:
Thomas Much

Method Summary
static java.lang.String getHomeDirectory()
          The home directory contains the user's data and applications.
static java.lang.String getJavaHome()
          The Java home directory contains the bin subdirectory and is needed to invoke the Java tools at runtime.
static java.lang.String getLocalPrefsDirectory()
          The local preferences directory contains configuration files that are shared by all users on the computer.
static java.lang.String getPrefsDirectory()
          The preferences directory contains the user's configuration files.
static java.lang.String getWorkingDirectory()
          The directory from which the application was launched is called the working directory.
static boolean isAMac()
           
static boolean isLinux()
           
static boolean isMacOS()
           
static boolean isMacOSX()
           
static boolean isOS2()
           
static boolean isWindows()
           
static void main(java.lang.String[] args)
          This is a small test case for all the methods in this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isMacOS

public static boolean isMacOS()
Returns:
true, if the application is running on Mac OS 8/9, false otherwise

isMacOSX

public static boolean isMacOSX()
Returns:
true, if the application is running on Mac OS X, false otherwise

isAMac

public static boolean isAMac()
Returns:
true, if the application is running on a Mac (OS 8, 9 or X), false otherwise

isLinux

public static boolean isLinux()
Returns:
true, if the application is running on Linux, false otherwise

isWindows

public static boolean isWindows()
Returns:
true, if the application is running on Windows, false otherwise

isOS2

public static boolean isOS2()
Returns:
true, if the application is running on OS/2, false otherwise

getHomeDirectory

public static java.lang.String getHomeDirectory()
The home directory contains the user's data and applications. On UNIX systems this directory is denoted by ~ and can be queried through the system property user.home.

Returns:
the user's home directory without a trailing path separator

getWorkingDirectory

public static java.lang.String getWorkingDirectory()
The directory from which the application was launched is called the working directory. Its path can be queried through the system property user.dir.

Returns:
the application's working directory without a trailing path separator

getPrefsDirectory

public static java.lang.String getPrefsDirectory()
The preferences directory contains the user's configuration files. On Mac OS X, this method returns ~/Library/Preferences, on all other systems the user's home directory is used.

Returns:
the user's preferences directory without a trailing path separator

getLocalPrefsDirectory

public static java.lang.String getLocalPrefsDirectory()
The local preferences directory contains configuration files that are shared by all users on the computer. On Mac OS X, this method returns /Library/Preferences, on Linux /etc. On all other systems the application's working directory is used. Please note: There is no guarantee that your application has permission to use this directory!

Returns:
the shared preferences directory (without a trailing path separator) of all users on a local computer

getJavaHome

public static java.lang.String getJavaHome()
The Java home directory contains the bin subdirectory and is needed to invoke the Java tools at runtime. It is specified by the environment variable $JAVA_HOME and can be queried through the system property java.home. If the variable is not set properly, this method returns /Library/Java/Home on Mac OS X.

Returns:
the Java home directory without a trailing path separator

main

public static void main(java.lang.String[] args)
This is a small test case for all the methods in this class. On Mac OS X you can launch it by simply double-clicking the jar file (output goes to the Console). On other systems, you can start it with java -classpath .:Sys.jar com.muchsoft.util.Sys (or java -jar Sys.jar)

Parameters:
args - not used