X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2Futil%2FPlatform.java;fp=src%2Forg%2Fibex%2Fnestedvm%2Futil%2FPlatform.java;h=e1f412ac764cb47c0aa8aa53eb422f68cab4618b;hp=0000000000000000000000000000000000000000;hb=a9b51184aec8670b8627a8be6e6be88014264d3b;hpb=4cc48f20c2927ad6d88f4d54e10b5fe46fcef2df diff --git a/src/org/ibex/nestedvm/util/Platform.java b/src/org/ibex/nestedvm/util/Platform.java new file mode 100644 index 0000000..e1f412a --- /dev/null +++ b/src/org/ibex/nestedvm/util/Platform.java @@ -0,0 +1,84 @@ +package org.ibex.nestedvm.util; + +import java.io.*; +import java.net.*; +import java.util.*; + +import java.text.DateFormatSymbols; + +public abstract class Platform { + Platform() { } + private static final Platform p=null; + + abstract boolean _atomicCreateFile(File f) throws IOException; + public static boolean atomicCreateFile(File f) throws IOException { return p._atomicCreateFile(f); } + + abstract void _socketHalfClose(Socket s, boolean output) throws IOException; + public static void socketHalfClose(Socket s, boolean output) throws IOException { p._socketHalfClose(s,output); } + + abstract void _socketSetKeepAlive(Socket s, boolean on) throws SocketException; + public static void socketSetKeepAlive(Socket s, boolean on) throws SocketException { p._socketSetKeepAlive(s,on); } + + abstract InetAddress _inetAddressFromBytes(byte[] a) throws UnknownHostException; + public static InetAddress inetAddressFromBytes(byte[] a) throws UnknownHostException { return p._inetAddressFromBytes(a); } + + abstract String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l); + 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()); } + + static class Jdk11 extends Platform { + boolean _atomicCreateFile(File f) throws IOException { + throw new Error("FIXME"); + } + void _socketHalfClose(Socket s, boolean output) throws IOException { + throw new IOException("half closing sockets not supported"); + } + InetAddress _inetAddressFromBytes(byte[] a) throws UnknownHostException { + if(a.length != 4) throw new UnknownHostException("only ipv4 addrs supported"); + return InetAddress.getByName(""+(a[0]&0xff)+"."+(a[1]&0xff)+"."+(a[2]&0xff)+"."+(a[3]&0xff)); + } + void _socketSetKeepAlive(Socket s, boolean on) throws SocketException { + if(on) throw new SocketException("keepalive not supported"); + } + String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) { + String[][] zs = new DateFormatSymbols(l).getZoneStrings(); + String id = tz.getID(); + for(int i=0;i 0) sb.append(":").append(off/60); off=off%60; + if(off > 0) sb.append(":").append(off); + return sb.toString(); + } + } + + static class Jdk12 extends Jdk11 { + boolean _atomicCreateFile(File f) throws IOException { + return f.createNewFile(); + } + + String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) { + return tz.getDisplayName(dst,showlong ? TimeZone.LONG : TimeZone.SHORT, l); + } + } + + static class Jdk13 extends Jdk12 { + void _socketHalfClose(Socket s, boolean output) throws IOException { + if(output) s.shutdownOutput(); + else s.shutdownInput(); + } + + void _socketSetKeepAlive(Socket s, boolean on) throws SocketException { + s.setKeepAlive(on); + } + } + + static class Jdk14 extends Jdk13 { + InetAddress _inetAddressFromBytes(byte[] a) throws UnknownHostException { return InetAddress.getByAddress(a); } + } +}