1*04ea5bd4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*04ea5bd4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*04ea5bd4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*04ea5bd4SAndrew Rist  * distributed with this work for additional information
6*04ea5bd4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*04ea5bd4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*04ea5bd4SAndrew Rist  * "License"); you may not use this file except in compliance
9*04ea5bd4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*04ea5bd4SAndrew Rist  *
11*04ea5bd4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*04ea5bd4SAndrew Rist  *
13*04ea5bd4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*04ea5bd4SAndrew Rist  * software distributed under the License is distributed on an
15*04ea5bd4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*04ea5bd4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*04ea5bd4SAndrew Rist  * specific language governing permissions and limitations
18*04ea5bd4SAndrew Rist  * under the License.
19*04ea5bd4SAndrew Rist  *
20*04ea5bd4SAndrew Rist  *************************************************************/
21*04ea5bd4SAndrew Rist 
22*04ea5bd4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import java.io.DataInput;
25cdf0e10cSrcweir import java.io.DataOutput;
26cdf0e10cSrcweir import java.io.IOException;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /**
29cdf0e10cSrcweir  *  <p>Class used only internally by <code>PDBEncoder</code> and
30cdf0e10cSrcweir  *  <code>PDBDecoder</code> to store, read and write a pdb header.</p>
31cdf0e10cSrcweir  *
32cdf0e10cSrcweir  *  <p>Note that fields are intended to be accessible only at the
33cdf0e10cSrcweir  *  package level.</p>
34cdf0e10cSrcweir  *
35cdf0e10cSrcweir  *  <p>Some of the fields are internally represented using a
36cdf0e10cSrcweir  *  larger type since Java does not have unsigned types.
37cdf0e10cSrcweir  *  Some are not since they are not relevant for now.
38cdf0e10cSrcweir  *  The <code>read</code> and <code>write</code> methods should
39cdf0e10cSrcweir  *  handle them properly.</p>
40cdf0e10cSrcweir  *
41cdf0e10cSrcweir  *  @author    Herbie Ong
42cdf0e10cSrcweir  */
43cdf0e10cSrcweir 
44cdf0e10cSrcweir final class PDBHeader {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     /** name of the database. 32 bytes. */
47cdf0e10cSrcweir     byte[] pdbName = null;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /** flags for the database. Palm UInt16. Unsignedness should be irrelevant. */
50cdf0e10cSrcweir     short attribute = 0;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     /** application-specific version for the database. Palm UInt16 */
53cdf0e10cSrcweir     int version = 0;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** date created. Palm UInt32 */
56cdf0e10cSrcweir     long creationDate = 0;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /** date last modified. Palm UInt32  */
59cdf0e10cSrcweir     long modificationDate = 0;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     /** date last backup. Palm UInt32 */
62cdf0e10cSrcweir     long lastBackupDate = 0;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     /**
65cdf0e10cSrcweir      *  incremented every time a record is
66cdf0e10cSrcweir      *  added, deleted or modified.  Palm UInt32.
67cdf0e10cSrcweir      */
68cdf0e10cSrcweir     long modificationNumber = 0;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /** optional field. Palm UInt32. Unsignedness should be irrelevant. */
71cdf0e10cSrcweir     int appInfoID = 0;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     /** optional field. Palm UInt32. Unsignedness should be irrelevant. */
74cdf0e10cSrcweir     int sortInfoID = 0;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     /** database type id. Palm UInt32. Unsignedness should be irrelevant. */
77cdf0e10cSrcweir     int typeID = 0;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /** database creator id. Palm UInt32. Unsignedness should be irrelevant. */
80cdf0e10cSrcweir     int creatorID = 0;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /** ??? */
83cdf0e10cSrcweir     int uniqueIDSeed = 0;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /** see numRecords. 4 bytes. */
86cdf0e10cSrcweir     int nextRecordListID = 0;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     /**
89cdf0e10cSrcweir      *  number of records stored in the database header.
90cdf0e10cSrcweir      *  If all the record entries cannot fit in the header,
91cdf0e10cSrcweir      *  then nextRecordList has the local ID of a
92cdf0e10cSrcweir      *  recordList that contains the next set of records.
93cdf0e10cSrcweir      *  Palm UInt16.
94cdf0e10cSrcweir      */
95cdf0e10cSrcweir     int numRecords = 0;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /**
98cdf0e10cSrcweir      *  Read in the data for the pdb header.  Need to
99cdf0e10cSrcweir      *  preserve the unsigned value for some of the fields.
100cdf0e10cSrcweir      *
101cdf0e10cSrcweir      *  @param   di    a DataInput object
102cdf0e10cSrcweir      *  @throws   IOException    if I/O error occurs
103cdf0e10cSrcweir      */
104cdf0e10cSrcweir 
read(DataInput in)105cdf0e10cSrcweir     public void read(DataInput in) throws IOException {
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         pdbName = new byte[PalmDB.NAME_LENGTH];
108cdf0e10cSrcweir         in.readFully(pdbName);
109cdf0e10cSrcweir         attribute = in.readShort();
110cdf0e10cSrcweir         version = in.readUnsignedShort();
111cdf0e10cSrcweir         creationDate = ((long) in.readInt()) & 0xffffffffL;
112cdf0e10cSrcweir         modificationDate = ((long) in.readInt()) & 0xffffffffL;
113cdf0e10cSrcweir         lastBackupDate = ((long) in.readInt())  & 0xffffffffL;
114cdf0e10cSrcweir         modificationNumber = ((long) in.readInt()) & 0xffffffffL;
115cdf0e10cSrcweir         appInfoID = in.readInt();
116cdf0e10cSrcweir         sortInfoID = in.readInt();
117cdf0e10cSrcweir         creatorID = in.readInt();
118cdf0e10cSrcweir         typeID = in.readInt();
119cdf0e10cSrcweir         uniqueIDSeed = in.readInt();
120cdf0e10cSrcweir         nextRecordListID = in.readInt();
121cdf0e10cSrcweir         numRecords = in.readUnsignedShort();
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     /**
125cdf0e10cSrcweir      *  Write out pdb header data.
126cdf0e10cSrcweir      *
127cdf0e10cSrcweir      *  @param   out    a DataOut object
128cdf0e10cSrcweir      *  @throws   IOException    if I/O error occurs
129cdf0e10cSrcweir      */
130cdf0e10cSrcweir 
write(DataOutput out)131cdf0e10cSrcweir     public void write(DataOutput out) throws IOException {
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         out.write(pdbName);
134cdf0e10cSrcweir         out.writeShort(attribute);
135cdf0e10cSrcweir         out.writeShort(version);
136cdf0e10cSrcweir         out.writeInt((int) creationDate);
137cdf0e10cSrcweir         out.writeInt((int) modificationDate);
138cdf0e10cSrcweir         out.writeInt((int) lastBackupDate);
139cdf0e10cSrcweir         out.writeInt((int) modificationNumber);
140cdf0e10cSrcweir         out.writeInt(appInfoID);
141cdf0e10cSrcweir         out.writeInt(sortInfoID);
142cdf0e10cSrcweir         out.writeInt(typeID);
143cdf0e10cSrcweir         out.writeInt(creatorID);
144cdf0e10cSrcweir         out.writeInt(uniqueIDSeed);
145cdf0e10cSrcweir         out.writeInt(nextRecordListID);
146cdf0e10cSrcweir         out.writeShort(numRecords);
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150