remove unnecessary annotations to calculate evalution numbers.
[IRC.git] / Robust / src / Benchmarks / SSJava / MP3Decoder / JavaLayerUtils.java
index 13f2ac0b6f48cfaf678d9d5ee79ae995cd987b9a..605e3f672f26f33cf4b932d388945cf6721508db 100644 (file)
-/*\r
- * 11/19/04            1.0 moved to LGPL.\r
- * 12/12/99            Initial version.        mdm@techie.com\r
- *-----------------------------------------------------------------------\r
- *   This program is free software; you can redistribute it and/or modify\r
- *   it under the terms of the GNU Library General Public License as published\r
- *   by the Free Software Foundation; either version 2 of the License, or\r
- *   (at your option) any later version.\r
- *\r
- *   This program is distributed in the hope that it will be useful,\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *   GNU Library General Public License for more details.\r
- *\r
- *   You should have received a copy of the GNU Library General Public\r
- *   License along with this program; if not, write to the Free Software\r
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- *----------------------------------------------------------------------\r
- */\r
-\r
-\r
-//import java.io.IOException;\r
-//import java.io.InputStream;\r
-//import java.io.InvalidClassException;\r
-//import java.io.InvalidObjectException;\r
-//import java.io.ObjectInputStream;\r
-//import java.io.ObjectOutputStream;\r
-//import java.io.OutputStream;\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
- * \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
-    }\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
-}\r
+/*
+ * 11/19/04            1.0 moved to LGPL.
+ * 12/12/99            Initial version.        mdm@techie.com
+ *-----------------------------------------------------------------------
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Library General Public License as published
+ *   by the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Library General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Library General Public
+ *   License along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+
+//import java.io.IOException;
+//import java.io.InputStream;
+//import java.io.InvalidClassException;
+//import java.io.InvalidObjectException;
+//import java.io.ObjectInputStream;
+//import java.io.ObjectOutputStream;
+//import java.io.OutputStream;
+//import java.lang.reflect.Array;
+
+/**
+ * The JavaLayerUtils class is not strictly part of the JavaLayer API.
+ * It serves to provide useful methods and system-wide hooks.
+ * 
+ * @author MDM
+ */
+public class JavaLayerUtils
+{
+       static private JavaLayerHook    hook = null;
+       
+       /**
+        * Deserializes the object contained in the given input stream.
+        * @param in    The input stream to deserialize an object from.
+        * @param cls   The expected class of the deserialized object. 
+        */
+//     static public Object deserialize(InputStream in, Class cls)
+       static public Object deserialize(InputStream in)
+               throws IOException
+       {
+//             if (cls==null)
+//                     throw new NullPointerException("cls");
+               
+//             Object obj = deserialize(in, cls);
+            Object obj = deserialize(in);
+//             if (!cls.isInstance(obj))
+//             {
+//                     throw new InvalidObjectException("type of deserialized instance not of required class.");
+//             }
+               
+               return obj;
+       }
+       
+       /**
+        * Deserializes an object from the given <code>InputStream</code>.
+        * The deserialization is delegated to an <code>
+        * ObjectInputStream</code> instance. 
+        * 
+        * @param in    The <code>InputStream</code> to deserialize an object
+        *                              from.
+        * 
+        * @return The object deserialized from the stream. 
+        * @exception IOException is thrown if there was a problem reading
+        *              the underlying stream, or an object could not be deserialized
+        *              from the stream.
+        * 
+        * @see java.io.ObjectInputStream
+        */
+       static public Object deserialize(InputStream in)
+               throws IOException
+       {
+               if (in==null)
+                       throw new NullPointerException("in");
+               
+               //TODO : need to enable after having objectinputstream
+               /*
+               ObjectInputStream objIn = new ObjectInputStream(in);
+               
+               Object obj;
+               
+               try
+               {
+                       obj = objIn.readObject();
+               }
+               catch (ClassNotFoundException ex)
+               {
+                       throw new InvalidClassException(ex.toString());
+               }
+               
+               return obj;
+               */
+               return null;
+       }
+
+       /**
+        * Deserializes an array from a given <code>InputStream</code>.
+        * 
+        * @param in            The <code>InputStream</code> to 
+        *                                      deserialize an object from.
+        *                              
+        * @param elemType      The class denoting the type of the array
+        *                                      elements.
+        * @param length        The expected length of the array, or -1 if
+        *                                      any length is expected.
+        */
+           static public Object deserializeArray(InputStream in, int length)
+         throws IOException
+    {
+         if (length<-1)
+              throw new IllegalArgumentException("length");
+         
+         Object obj = deserialize(in);
+         
+         return obj;
+    }
+//     static public Object deserializeArray(InputStream in, Class elemType, int length)
+//             throws IOException
+//     {
+//             if (elemType==null)
+//                     throw new NullPointerException("elemType");
+//             
+//             if (length<-1)
+//                     throw new IllegalArgumentException("length");
+//             
+//             Object obj = deserialize(in);
+//             
+//             //SSJava will never throw exceptions as it is so this code is meaningless
+//             /*
+//             Class cls = obj.getClass();
+//             
+//             if (!cls.isArray())
+//                     throw new InvalidObjectException("object is not an array");
+//             
+//             Class arrayElemType = cls.getComponentType();
+//             if (arrayElemType!=elemType)
+//                     throw new InvalidObjectException("unexpected array component type");
+//                             
+//             if (length != -1)
+//             {
+//                     int arrayLength = Array.getLength(obj);
+//                     if (arrayLength!=length)
+//                             throw new InvalidObjectException("array length mismatch");
+//             }
+//             */
+//             return obj;
+//     }
+
+//     static public Object deserializeArrayResource(String name, Class elemType, int length)
+           static public Object deserializeArrayResource(String name, int length)
+               throws IOException
+       {               
+               InputStream str = getResourceAsStream(name);
+               if (str==null)
+                       throw new IOException("unable to load resource '"+name+"'");
+               
+//             Object obj = deserializeArray(str, elemType, length);
+               Object obj = deserializeArray(str, length);
+               
+               return obj;
+       }       
+       
+       static public void serialize(OutputStream out, Object obj)
+               throws IOException
+       {
+       //TODO : need to enable after having objectinputstream
+//             if (out==null)
+//                     throw new NullPointerException("out");
+//             
+//             if (obj==null)
+//                     throw new NullPointerException("obj");
+//             
+//             ObjectOutputStream objOut = new ObjectOutputStream(out);
+//             objOut.writeObject(obj);
+                               
+       }
+
+       /**
+        * Sets the system-wide JavaLayer hook.
+        */
+       static synchronized public void setHook(JavaLayerHook hook0)            
+       {
+               hook = hook0;
+       }
+       
+       static synchronized public JavaLayerHook getHook()
+       {
+               return hook;    
+       }
+       
+       /**
+        * Retrieves an InputStream for a named resource. 
+        * 
+        * @param name  The name of the resource. This must be a simple
+        *                              name, and not a qualified package name.
+        * 
+        * @return              The InputStream for the named resource, or null if
+        *                              the resource has not been found. If a hook has been 
+        *                              provided, its getResourceAsStream() method is called
+        *                              to retrieve the resource. 
+        */
+       static synchronized public InputStream getResourceAsStream(String name)
+       {
+               InputStream is = null;
+               
+               if (hook!=null)
+               {
+                       is = hook.getResourceAsStream(name);    
+               }
+               //TODO java reflection
+//             else
+//             {
+//                     Class cls = JavaLayerUtils.class;
+//                     is = cls.getResourceAsStream(name);
+//             }
+               
+               return is;              
+       }
+}