SystemUtils.java

00001 package edu.stanford.hci.r3.util;
00002 
00003 import java.io.File;
00004 import java.net.URISyntaxException;
00005 import java.net.URL;
00006 
00018 public class SystemUtils {
00019 
00020         private static final double BYTES_PER_MB = (1024.0 * 1024.0);
00021 
00026         public static final String LIBRARY_PATH_KEY = "java.library.path";
00027 
00031         public static final String LINE_SEPARATOR = System.getProperties()
00032                         .getProperty("line.separator");
00033 
00037         public static final String PATH_SEPARATOR = System.getProperty("path.separator");
00038 
00039         private static long previousTime;
00040 
00050         public static void addToLibraryPath(URL url) {
00051                 try {
00052                         final String newPath = new File(url.toURI()).getAbsolutePath() + PATH_SEPARATOR
00053                                         + System.getProperty(LIBRARY_PATH_KEY);
00054                         System.setProperty(LIBRARY_PATH_KEY, newPath);
00055                         System.out.println(System.getProperty(LIBRARY_PATH_KEY));
00056                 } catch (URISyntaxException e) {
00057                         e.printStackTrace();
00058                 }
00059         }
00060 
00064         public static double getFreeMemoryInMB() {
00065                 return Runtime.getRuntime().freeMemory() / BYTES_PER_MB;
00066         }
00067 
00071         public static File getWorkingDirectory() {
00072                 return new File(System.getProperty("user.dir"));
00073         }
00074 
00080         public static boolean operatingSystemIsMacOSX() {
00081                 String lcOSName = System.getProperty("os.name").toLowerCase();
00082                 return lcOSName.startsWith("mac os x");
00083         }
00084 
00088         public static boolean operatingSystemIsWindowsVariant() {
00089                 String lcOSName = System.getProperty("os.name").toLowerCase();
00090                 return lcOSName.startsWith("windows");
00091         }
00092 
00113         public static void setWorkingDirectory(File file) {
00114                 System.setProperty("user.dir", file.getAbsolutePath());
00115         }
00116 
00120         public static void tic() {
00121                 previousTime = System.currentTimeMillis();
00122         }
00123 
00127         public static void toc() {
00128                 DebugUtils.println("Clock: " + (System.currentTimeMillis() - previousTime) + " ms.");
00129         }
00130 
00131 }

Generated on Sat Apr 14 18:21:39 2007 for R3 Paper Toolkit by  doxygen 1.4.7