cleanup elf stuff
[nestedvm.git] / src / org / ibex / nestedvm / util / Platform.java
index f9dca10..448cf45 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
 package org.ibex.nestedvm.util;
 
 import java.io.*;
@@ -6,6 +10,13 @@ import java.util.*;
 
 import java.text.DateFormatSymbols;
 
+/*
+ GCCLASS_HINT: org.ibex.nestedvm.util.Platform.<clinit> org.ibex.nestedvm.util.Platform$Jdk11.<init>
+ GCCLASS_HINT: org.ibex.nestedvm.util.Platform.<clinit> org.ibex.nestedvm.util.Platform$Jdk12.<init>
+ GCCLASS_HINT: org.ibex.nestedvm.util.Platform.<clinit> org.ibex.nestedvm.util.Platform$Jdk13.<init>
+ GCCLASS_HINT: org.ibex.nestedvm.util.Platform.<clinit> org.ibex.nestedvm.util.Platform$Jdk14.<init>
+*/
+
 public abstract class Platform {
     Platform() { }
     private static final Platform p;
@@ -13,7 +24,10 @@ public abstract class Platform {
     static {
         float version;
         try {
-            version = Float.parseFloat(System.getProperty("java.specification.version"));
+            if(getProperty("java.vm.name").equals("SableVM"))
+                version = 1.2f;
+            else
+                version = Float.valueOf(getProperty("java.specification.version")).floatValue();
         } catch(Exception e) {
             System.err.println("WARNING: " + e + " while trying to find jvm version -  assuming 1.1");
             version = 1.1f;
@@ -33,6 +47,15 @@ public abstract class Platform {
         }
     }
     
+    public static String getProperty(String key) {
+        try {
+            return System.getProperty(key);
+        } catch(SecurityException e) {
+            return null;
+        }
+    }
+    
+    
     abstract boolean _atomicCreateFile(File f) throws IOException;
     public static boolean atomicCreateFile(File f) throws IOException { return p._atomicCreateFile(f); }
     
@@ -49,10 +72,15 @@ public abstract class Platform {
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) { return p._timeZoneGetDisplayName(tz,dst,showlong,l); }
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong) { return timeZoneGetDisplayName(tz,dst,showlong,Locale.getDefault()); }
     
+    abstract RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException;
+    public static RandomAccessFile truncatedRandomAccessFile(File f, String mode) throws IOException { return p._truncatedRandomAccessFile(f,mode); }
+    
     static class Jdk11 extends Platform {
         boolean _atomicCreateFile(File f) throws IOException {
-            // FIXME: Just do this non-atomicly
-            throw new RuntimeException("FIXME");
+            // This is not atomic, but its the best we can do on jdk 1.1
+            if(f.exists()) return false;
+            new FileOutputStream(f).close();
+            return true;
         }
         void _socketHalfClose(Socket s, boolean output) throws IOException {
             throw new IOException("half closing sockets not supported");
@@ -79,6 +107,11 @@ public abstract class Platform {
             if(off > 0) sb.append(":").append(off);
             return sb.toString();
         }
+        
+        RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException {
+            new FileOutputStream(f).close();
+            return new RandomAccessFile(f,mode);
+        }
     }
     
     static class Jdk12 extends Jdk11 {
@@ -89,6 +122,12 @@ public abstract class Platform {
         String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) {
             return tz.getDisplayName(dst,showlong ? TimeZone.LONG : TimeZone.SHORT, l);
         }
+        
+        RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException {
+            RandomAccessFile raf = new RandomAccessFile(f,mode);
+            raf.setLength(0);
+            return raf;
+        }       
     }
     
     static class Jdk13 extends Jdk12 {