--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.services.io.FormatableIntHolder\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 org.apache.derby.iapi.services.io.ArrayInputStream;\r
+\r
+import org.apache.derby.iapi.services.io.Formatable;\r
+import org.apache.derby.iapi.services.io.FormatIdUtil;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import java.io.ObjectOutput;\r
+import java.io.ObjectInput;\r
+import java.io.IOException;\r
+\r
+/**\r
+ * A formatable holder for an int.\r
+ */\r
+public class FormatableIntHolder implements Formatable\r
+{\r
+ /********************************************************\r
+ **\r
+ ** This class implements Formatable. That means that it\r
+ ** can write itself to and from a formatted stream. If\r
+ ** you add more fields to this class, make sure that you\r
+ ** also write/read them with the writeExternal()/readExternal()\r
+ ** methods.\r
+ **\r
+ ** If, inbetween releases, you add more fields to this class,\r
+ ** then you should bump the version number emitted by the getTypeFormatId()\r
+ ** method.\r
+ **\r
+ ********************************************************/\r
+\r
+ // the int\r
+ private int theInt;\r
+ \r
+ /**\r
+ * Niladic constructor for formatable\r
+ */\r
+ public FormatableIntHolder() \r
+ {\r
+ }\r
+\r
+ /**\r
+ * Construct a FormatableIntHolder using the input int.\r
+ *\r
+ * @param theInt the int to hold\r
+ */\r
+ public FormatableIntHolder(int theInt)\r
+ {\r
+ this.theInt = theInt;\r
+ }\r
+\r
+ /**\r
+ * Set the held int to the input int.\r
+ *\r
+ * @param theInt the int to hold\r
+ */\r
+ public void setInt(int theInt)\r
+ {\r
+ this.theInt = theInt;\r
+ }\r
+\r
+ /**\r
+ * Get the held int.\r
+ *\r
+ * @return The held int.\r
+ */\r
+ public int getInt()\r
+ {\r
+ return theInt;\r
+ }\r
+\r
+ /**\r
+ * Create and return an array of FormatableIntHolders\r
+ * given an array of ints.\r
+ *\r
+ * @param theInts The array of ints\r
+ *\r
+ * @return An array of FormatableIntHolders\r
+ */\r
+ public static FormatableIntHolder[] getFormatableIntHolders(int[] theInts)\r
+ {\r
+ if (theInts == null)\r
+ {\r
+ return null;\r
+ }\r
+\r
+ FormatableIntHolder[] fihArray = new FormatableIntHolder[theInts.length];\r
+\r
+ for (int index = 0; index < theInts.length; index++)\r
+ {\r
+ fihArray[index] = new FormatableIntHolder(theInts[index]);\r
+ }\r
+ return fihArray;\r
+ }\r
+\r
+ //////////////////////////////////////////////\r
+ //\r
+ // FORMATABLE\r
+ //\r
+ //////////////////////////////////////////////\r
+ /**\r
+ * Write this formatable out\r
+ *\r
+ * @param out write bytes here\r
+ *\r
+ * @exception IOException thrown on error\r
+ */\r
+ public void writeExternal(ObjectOutput out) throws IOException\r
+ {\r
+ out.writeInt(theInt);\r
+ }\r
+\r
+ /**\r
+ * Read this formatable from a stream of stored objects.\r
+ *\r
+ * @param in read this.\r
+ *\r
+ * @exception IOException thrown on error\r
+ */\r
+ public void readExternal(ObjectInput in)\r
+ throws IOException\r
+ {\r
+ theInt = in.readInt();\r
+ }\r
+ public void readExternal(ArrayInputStream in)\r
+ throws IOException\r
+ {\r
+ theInt = in.readInt();\r
+ }\r
+ \r
+ /**\r
+ * Get the formatID which corresponds to this class.\r
+ *\r
+ * @return the formatID of this class\r
+ */\r
+ public int getTypeFormatId() { return StoredFormatIds.FORMATABLE_INT_HOLDER_V01_ID; }\r
+}\r