Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / services / classfile / ClassFormatOutput.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/services/classfile/ClassFormatOutput.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/services/classfile/ClassFormatOutput.java
new file mode 100644 (file)
index 0000000..7bd403d
--- /dev/null
@@ -0,0 +1,103 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.services.classfile.ClassFormatOutput\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.services.classfile;\r
+\r
+import org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream;\r
+import java.io.DataOutputStream;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+\r
+/** A wrapper around DataOutputStream to provide input functions in terms\r
+    of the types defined on pages 83 of the Java Virtual Machine spec.\r
+\r
+       For this types use these methods of DataOutputStream\r
+       <UL>\r
+       <LI>float - writeFloat\r
+       <LI>long - writeLong\r
+       <LI>double - writeDouble\r
+       <LI>UTF/String - writeUTF\r
+       <LI>U1Array - write(byte[])\r
+       </UL>\r
+ */\r
+\r
+public final class ClassFormatOutput extends DataOutputStream {\r
+\r
+       public ClassFormatOutput() {\r
+               this(512);\r
+       }\r
+\r
+       public ClassFormatOutput(int size) {\r
+               this(new AccessibleByteArrayOutputStream(size));\r
+       }\r
+       public ClassFormatOutput(java.io.OutputStream stream) {\r
+               super(stream);\r
+       }\r
+       public void putU1(int i) throws IOException {\r
+               // ensure the format of the class file is not\r
+               // corrupted by writing an incorrect, truncated value.\r
+               if (i > 255)\r
+                       ClassFormatOutput.limit("U1", 255, i);\r
+               write(i);\r
+       }\r
+       public void putU2(int i) throws IOException {\r
+               putU2("U2", i);\r
+\r
+       }\r
+       public void putU2(String limit, int i) throws IOException {\r
+               \r
+               // ensure the format of the class file is not\r
+               // corrupted by writing an incorrect, truncated value.\r
+               if (i > 65535)\r
+                       ClassFormatOutput.limit(limit, 65535, i);\r
+               write(i >> 8);\r
+               write(i);\r
+       }\r
+       public void putU4(int i) throws IOException {\r
+               writeInt(i);\r
+       }\r
+\r
+       public void writeTo(OutputStream outTo) throws IOException {\r
+               ((AccessibleByteArrayOutputStream) out).writeTo(outTo);\r
+       }\r
+\r
+       /**\r
+               Get a reference to the data array the class data is being built\r
+               in. No copy is made.\r
+       */\r
+       public byte[] getData() {\r
+               return ((AccessibleByteArrayOutputStream) out).getInternalByteArray();\r
+       }\r
+\r
+       /**\r
+        * Throw an ClassFormatError if a limit of the Java class file format is reached.\r
+        * @param name Terse limit description from JVM spec.\r
+        * @param limit What the limit is.\r
+        * @param value What the value for the current class is\r
+        * @throws IOException Thrown when limit is exceeded.\r
+        */\r
+       static void limit(String name, int limit, int value)\r
+               throws IOException\r
+       {\r
+               throw new IOException(name + "(" + value + " > " + limit + ")");\r
+       }\r
+}\r