--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.services.io.FormatIdUtil\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.DataInput;\r
+import java.io.DataOutput;\r
+import java.io.IOException;\r
+\r
+/**\r
+ Utility class with static methods for constructing and reading the byte array\r
+ representation of format id's.\r
+\r
+ <P>This utility supports a number of families of format ids. The byte array\r
+ form of each family is a different length. In all cases the first two bits\r
+ of the first byte indicate the family for an id. The list below describes\r
+ each family and gives its two bit identifier in parens.\r
+\r
+ <UL> \r
+ <LI> (0) - The format id is a one byte number between 0 and 63 inclusive. \r
+ The byte[] encoding fits in one byte.\r
+ <LI> (1) - The format id is a two byte number between 16384 to 32767\r
+ inclusive. The byte[] encoding stores the high order byte\r
+ first. \r
+ <LI> (2) - The format id is four byte number between 2147483648 and\r
+ 3221225471 inclusive. The byte[] encoding stores the high\r
+ order byte first.\r
+ <LI> (3) - Future expansion.\r
+ </UL>\r
+ */\r
+public final class FormatIdUtil\r
+{\r
+ private FormatIdUtil() {\r
+ }\r
+\r
+ public static int getFormatIdByteLength(int formatId) {\r
+ return 2;\r
+ }\r
+\r
+ public static void writeFormatIdInteger(DataOutput out, int formatId) throws IOException {\r
+ out.writeShort(formatId);\r
+ }\r
+\r
+ public static int readFormatIdInteger(DataInput in)\r
+ throws IOException {\r
+\r
+ return in.readUnsignedShort();\r
+ }\r
+\r
+ public static int readFormatIdInteger(byte[] data) {\r
+\r
+ int a = data[0];\r
+ int b = data[1];\r
+ return (((a & 0xff) << 8) | (b & 0xff));\r
+ }\r
+\r
+ public static String formatIdToString(int fmtId) {\r
+\r
+ return Integer.toString(fmtId);\r
+ }\r
+}\r