*----------------------------------------------------------------------\r
*/\r
\r
-\r
//import java.io.IOException;\r
//import java.io.InputStream;\r
//import java.io.InvalidClassException;\r
//import java.lang.reflect.Array;\r
\r
/**\r
- * The JavaLayerUtils class is not strictly part of the JavaLayer API.\r
- * It serves to provide useful methods and system-wide hooks.\r
+ * The JavaLayerUtils class is not strictly part of the JavaLayer API. It serves\r
+ * to provide useful methods and system-wide hooks.\r
* \r
* @author MDM\r
*/\r
-public class JavaLayerUtils\r
-{\r
- static private JavaLayerHook hook = null;\r
- \r
- /**\r
- * Deserializes the object contained in the given input stream.\r
- * @param in The input stream to deserialize an object from.\r
- * @param cls The expected class of the deserialized object. \r
- */\r
-// static public Object deserialize(InputStream in, Class cls)\r
- static public Object deserialize(InputStream in)\r
- throws IOException\r
- {\r
-// if (cls==null)\r
-// throw new NullPointerException("cls");\r
- \r
-// Object obj = deserialize(in, cls);\r
- Object obj = deserialize(in);\r
-// if (!cls.isInstance(obj))\r
-// {\r
-// throw new InvalidObjectException("type of deserialized instance not of required class.");\r
-// }\r
- \r
- return obj;\r
- }\r
- \r
- /**\r
- * Deserializes an object from the given <code>InputStream</code>.\r
- * The deserialization is delegated to an <code>\r
- * ObjectInputStream</code> instance. \r
- * \r
- * @param in The <code>InputStream</code> to deserialize an object\r
- * from.\r
- * \r
- * @return The object deserialized from the stream. \r
- * @exception IOException is thrown if there was a problem reading\r
- * the underlying stream, or an object could not be deserialized\r
- * from the stream.\r
- * \r
- * @see java.io.ObjectInputStream\r
- */\r
- static public Object deserialize(InputStream in)\r
- throws IOException\r
- {\r
- if (in==null)\r
- throw new NullPointerException("in");\r
- \r
- //TODO : need to enable after having objectinputstream\r
- /*\r
- ObjectInputStream objIn = new ObjectInputStream(in);\r
- \r
- Object obj;\r
- \r
- try\r
- {\r
- obj = objIn.readObject();\r
- }\r
- catch (ClassNotFoundException ex)\r
- {\r
- throw new InvalidClassException(ex.toString());\r
- }\r
- \r
- return obj;\r
- */\r
- return null;\r
- }\r
-\r
- /**\r
- * Deserializes an array from a given <code>InputStream</code>.\r
- * \r
- * @param in The <code>InputStream</code> to \r
- * deserialize an object from.\r
- * \r
- * @param elemType The class denoting the type of the array\r
- * elements.\r
- * @param length The expected length of the array, or -1 if\r
- * any length is expected.\r
- */\r
- static public Object deserializeArray(InputStream in, int length)\r
- throws IOException\r
- {\r
- if (length<-1)\r
- throw new IllegalArgumentException("length");\r
- \r
- Object obj = deserialize(in);\r
- \r
- return obj;\r
+public class JavaLayerUtils {\r
+ static private JavaLayerHook hook = null;\r
+\r
+ /**\r
+ * Deserializes the object contained in the given input stream.\r
+ * \r
+ * @param in\r
+ * The input stream to deserialize an object from.\r
+ * @param cls\r
+ * The expected class of the deserialized object.\r
+ */\r
+ // static public Object deserialize(InputStream in, Class cls)\r
+ static public Object deserialize(InputStream in) throws IOException {\r
+ // if (cls==null)\r
+ // throw new NullPointerException("cls");\r
+\r
+ // Object obj = deserialize(in, cls);\r
+ Object obj = deserialize(in);\r
+ // if (!cls.isInstance(obj))\r
+ // {\r
+ // throw new\r
+ // InvalidObjectException("type of deserialized instance not of required class.");\r
+ // }\r
+\r
+ return obj;\r
+ }\r
+\r
+ /**\r
+ * Deserializes an object from the given <code>InputStream</code>. The\r
+ * deserialization is delegated to an <code>\r
+ * ObjectInputStream</code> instance.\r
+ * \r
+ * @param in\r
+ * The <code>InputStream</code> to deserialize an object from.\r
+ * \r
+ * @return The object deserialized from the stream.\r
+ * @exception IOException\r
+ * is thrown if there was a problem reading the underlying\r
+ * stream, or an object could not be deserialized from the\r
+ * stream.\r
+ * \r
+ * @see java.io.ObjectInputStream\r
+ */\r
+ static public Object deserialize(InputStream in) throws IOException {\r
+ if (in == null)\r
+ throw new NullPointerException("in");\r
+\r
+ // TODO : need to enable after having objectinputstream\r
+ /*\r
+ * ObjectInputStream objIn = new ObjectInputStream(in);\r
+ * \r
+ * Object obj;\r
+ * \r
+ * try { obj = objIn.readObject(); } catch (ClassNotFoundException ex) {\r
+ * throw new InvalidClassException(ex.toString()); }\r
+ * \r
+ * return obj;\r
+ */\r
+ return null;\r
+ }\r
+\r
+ /**\r
+ * Deserializes an array from a given <code>InputStream</code>.\r
+ * \r
+ * @param in\r
+ * The <code>InputStream</code> to deserialize an object from.\r
+ * \r
+ * @param elemType\r
+ * The class denoting the type of the array elements.\r
+ * @param length\r
+ * The expected length of the array, or -1 if any length is expected.\r
+ */\r
+ static public Object deserializeArray(InputStream in, int length) throws IOException {\r
+ if (length < -1)\r
+ throw new IllegalArgumentException("length");\r
+\r
+ Object obj = deserialize(in);\r
+\r
+ return obj;\r
+ }\r
+\r
+ // static public Object deserializeArray(InputStream in, Class elemType, int\r
+ // length)\r
+ // throws IOException\r
+ // {\r
+ // if (elemType==null)\r
+ // throw new NullPointerException("elemType");\r
+ //\r
+ // if (length<-1)\r
+ // throw new IllegalArgumentException("length");\r
+ //\r
+ // Object obj = deserialize(in);\r
+ //\r
+ // //SSJava will never throw exceptions as it is so this code is meaningless\r
+ // /*\r
+ // Class cls = obj.getClass();\r
+ //\r
+ // if (!cls.isArray())\r
+ // throw new InvalidObjectException("object is not an array");\r
+ //\r
+ // Class arrayElemType = cls.getComponentType();\r
+ // if (arrayElemType!=elemType)\r
+ // throw new InvalidObjectException("unexpected array component type");\r
+ //\r
+ // if (length != -1)\r
+ // {\r
+ // int arrayLength = Array.getLength(obj);\r
+ // if (arrayLength!=length)\r
+ // throw new InvalidObjectException("array length mismatch");\r
+ // }\r
+ // */\r
+ // return obj;\r
+ // }\r
+\r
+ // static public Object deserializeArrayResource(String name, Class elemType,\r
+ // int length)\r
+ static public Object deserializeArrayResource(String name, int length) throws IOException {\r
+ InputStream str = getResourceAsStream(name);\r
+ if (str == null)\r
+ throw new IOException("unable to load resource '" + name + "'");\r
+\r
+ // Object obj = deserializeArray(str, elemType, length);\r
+ Object obj = deserializeArray(str, length);\r
+\r
+ return obj;\r
+ }\r
+\r
+ static public void serialize(OutputStream out, Object obj) throws IOException {\r
+ // TODO : need to enable after having objectinputstream\r
+ // if (out==null)\r
+ // throw new NullPointerException("out");\r
+ //\r
+ // if (obj==null)\r
+ // throw new NullPointerException("obj");\r
+ //\r
+ // ObjectOutputStream objOut = new ObjectOutputStream(out);\r
+ // objOut.writeObject(obj);\r
+\r
+ }\r
+\r
+ /**\r
+ * Sets the system-wide JavaLayer hook.\r
+ */\r
+ static synchronized public void setHook(JavaLayerHook hook0) {\r
+ hook = hook0;\r
+ }\r
+\r
+ static synchronized public JavaLayerHook getHook() {\r
+ return hook;\r
+ }\r
+\r
+ /**\r
+ * Retrieves an InputStream for a named resource.\r
+ * \r
+ * @param name\r
+ * The name of the resource. This must be a simple name, and not a\r
+ * qualified package name.\r
+ * \r
+ * @return The InputStream for the named resource, or null if the resource has\r
+ * not been found. If a hook has been provided, its\r
+ * getResourceAsStream() method is called to retrieve the resource.\r
+ */\r
+ static synchronized public InputStream getResourceAsStream(String name) {\r
+ InputStream is = null;\r
+\r
+ if (hook != null) {\r
+ is = hook.getResourceAsStream(name);\r
}\r
-// static public Object deserializeArray(InputStream in, Class elemType, int length)\r
-// throws IOException\r
-// {\r
-// if (elemType==null)\r
-// throw new NullPointerException("elemType");\r
-// \r
-// if (length<-1)\r
-// throw new IllegalArgumentException("length");\r
-// \r
-// Object obj = deserialize(in);\r
-// \r
-// //SSJava will never throw exceptions as it is so this code is meaningless\r
-// /*\r
-// Class cls = obj.getClass();\r
-// \r
-// if (!cls.isArray())\r
-// throw new InvalidObjectException("object is not an array");\r
-// \r
-// Class arrayElemType = cls.getComponentType();\r
-// if (arrayElemType!=elemType)\r
-// throw new InvalidObjectException("unexpected array component type");\r
-// \r
-// if (length != -1)\r
-// {\r
-// int arrayLength = Array.getLength(obj);\r
-// if (arrayLength!=length)\r
-// throw new InvalidObjectException("array length mismatch");\r
-// }\r
-// */\r
-// return obj;\r
-// }\r
-\r
-// static public Object deserializeArrayResource(String name, Class elemType, int length)\r
- static public Object deserializeArrayResource(String name, int length)\r
- throws IOException\r
- { \r
- InputStream str = getResourceAsStream(name);\r
- if (str==null)\r
- throw new IOException("unable to load resource '"+name+"'");\r
- \r
-// Object obj = deserializeArray(str, elemType, length);\r
- Object obj = deserializeArray(str, length);\r
- \r
- return obj;\r
- } \r
- \r
- static public void serialize(OutputStream out, Object obj)\r
- throws IOException\r
- {\r
- //TODO : need to enable after having objectinputstream\r
-// if (out==null)\r
-// throw new NullPointerException("out");\r
-// \r
-// if (obj==null)\r
-// throw new NullPointerException("obj");\r
-// \r
-// ObjectOutputStream objOut = new ObjectOutputStream(out);\r
-// objOut.writeObject(obj);\r
- \r
- }\r
-\r
- /**\r
- * Sets the system-wide JavaLayer hook.\r
- */\r
- static synchronized public void setHook(JavaLayerHook hook0) \r
- {\r
- hook = hook0;\r
- }\r
- \r
- static synchronized public JavaLayerHook getHook()\r
- {\r
- return hook; \r
- }\r
- \r
- /**\r
- * Retrieves an InputStream for a named resource. \r
- * \r
- * @param name The name of the resource. This must be a simple\r
- * name, and not a qualified package name.\r
- * \r
- * @return The InputStream for the named resource, or null if\r
- * the resource has not been found. If a hook has been \r
- * provided, its getResourceAsStream() method is called\r
- * to retrieve the resource. \r
- */\r
- static synchronized public InputStream getResourceAsStream(String name)\r
- {\r
- InputStream is = null;\r
- \r
- if (hook!=null)\r
- {\r
- is = hook.getResourceAsStream(name); \r
- }\r
- //TODO java reflection\r
-// else\r
-// {\r
-// Class cls = JavaLayerUtils.class;\r
-// is = cls.getResourceAsStream(name);\r
-// }\r
- \r
- return is; \r
- }\r
+ // TODO java reflection\r
+ // else\r
+ // {\r
+ // Class cls = JavaLayerUtils.class;\r
+ // is = cls.getResourceAsStream(name);\r
+ // }\r
+\r
+ return is;\r
+ }\r
}\r