Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / iapi / services / io / ArrayOutputStream.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/io/ArrayOutputStream.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/services/io/ArrayOutputStream.java
new file mode 100644 (file)
index 0000000..95299cf
--- /dev/null
@@ -0,0 +1,120 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.services.io.ArrayOutputStream\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.io;\r
+\r
+import java.io.IOException;\r
+import java.io.EOFException;\r
+import java.io.OutputStream;\r
+\r
+public class ArrayOutputStream extends OutputStream implements Limit {\r
+\r
+       private byte[] pageData;\r
+\r
+       private int             start;\r
+       private int             end;            // exclusive\r
+       private int             position;\r
+\r
+       public ArrayOutputStream() {\r
+               super();\r
+       }\r
+\r
+       public ArrayOutputStream(byte[] data) {\r
+               super();\r
+               setData(data);\r
+       }\r
+\r
+       public void setData(byte[] data) {\r
+               pageData = data;\r
+               start = 0;\r
+               if (data != null)\r
+                       end = data.length;\r
+               else\r
+                       end = 0;\r
+               position = 0;\r
+\r
+       }\r
+\r
+       /*\r
+       ** Methods of OutputStream\r
+       */\r
+\r
+       public void write(int b) throws IOException {\r
+               if (position >= end)\r
+                       throw new EOFException();\r
+\r
+               pageData[position++] = (byte) b;\r
+\r
+       }\r
+\r
+       public void write(byte b[], int off, int len) throws IOException {\r
+\r
+               if ((position + len) > end)\r
+                       throw new EOFException();\r
+\r
+               System.arraycopy(b, off, pageData, position, len);\r
+               position += len;\r
+       }\r
+\r
+       /*\r
+       ** Methods of LengthOutputStream\r
+       */\r
+\r
+       public int getPosition() {\r
+               return position;\r
+       }\r
+\r
+       /**\r
+               Set the position of the stream pointer.\r
+       */\r
+       public void setPosition(int newPosition)\r
+               throws IOException {\r
+               if ((newPosition < start) || (newPosition > end))\r
+                       throw new EOFException();\r
+\r
+               position = newPosition;\r
+       }\r
+\r
+       public void setLimit(int length) throws IOException {\r
+\r
+               if (length < 0) {\r
+                       throw new EOFException();\r
+               }\r
+\r
+               if ((position + length) > end) {\r
+                       throw new EOFException();\r
+               }\r
+\r
+               start = position;\r
+               end = position + length;\r
+\r
+               return;\r
+       }\r
+\r
+       public int clearLimit() {\r
+\r
+               int unwritten = end - position;\r
+\r
+               end = pageData.length;\r
+\r
+               return unwritten;\r
+       }\r
+}\r