1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir import java.io.DataInput; 29*cdf0e10cSrcweir import java.io.DataOutput; 30*cdf0e10cSrcweir import java.io.IOException; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir /** 33*cdf0e10cSrcweir * <p>Class used only internally by <code>PDBEncoder</code> and 34*cdf0e10cSrcweir * <code>PDBDecoder</code> to store, read and write a pdb header.</p> 35*cdf0e10cSrcweir * 36*cdf0e10cSrcweir * <p>Note that fields are intended to be accessible only at the 37*cdf0e10cSrcweir * package level.</p> 38*cdf0e10cSrcweir * 39*cdf0e10cSrcweir * <p>Some of the fields are internally represented using a 40*cdf0e10cSrcweir * larger type since Java does not have unsigned types. 41*cdf0e10cSrcweir * Some are not since they are not relevant for now. 42*cdf0e10cSrcweir * The <code>read</code> and <code>write</code> methods should 43*cdf0e10cSrcweir * handle them properly.</p> 44*cdf0e10cSrcweir * 45*cdf0e10cSrcweir * @author Herbie Ong 46*cdf0e10cSrcweir */ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir final class PDBHeader { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir /** name of the database. 32 bytes. */ 51*cdf0e10cSrcweir byte[] pdbName = null; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** flags for the database. Palm UInt16. Unsignedness should be irrelevant. */ 54*cdf0e10cSrcweir short attribute = 0; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir /** application-specific version for the database. Palm UInt16 */ 57*cdf0e10cSrcweir int version = 0; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir /** date created. Palm UInt32 */ 60*cdf0e10cSrcweir long creationDate = 0; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** date last modified. Palm UInt32 */ 63*cdf0e10cSrcweir long modificationDate = 0; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir /** date last backup. Palm UInt32 */ 66*cdf0e10cSrcweir long lastBackupDate = 0; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir /** 69*cdf0e10cSrcweir * incremented every time a record is 70*cdf0e10cSrcweir * added, deleted or modified. Palm UInt32. 71*cdf0e10cSrcweir */ 72*cdf0e10cSrcweir long modificationNumber = 0; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir /** optional field. Palm UInt32. Unsignedness should be irrelevant. */ 75*cdf0e10cSrcweir int appInfoID = 0; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /** optional field. Palm UInt32. Unsignedness should be irrelevant. */ 78*cdf0e10cSrcweir int sortInfoID = 0; 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir /** database type id. Palm UInt32. Unsignedness should be irrelevant. */ 81*cdf0e10cSrcweir int typeID = 0; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /** database creator id. Palm UInt32. Unsignedness should be irrelevant. */ 84*cdf0e10cSrcweir int creatorID = 0; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /** ??? */ 87*cdf0e10cSrcweir int uniqueIDSeed = 0; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** see numRecords. 4 bytes. */ 90*cdf0e10cSrcweir int nextRecordListID = 0; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir /** 93*cdf0e10cSrcweir * number of records stored in the database header. 94*cdf0e10cSrcweir * If all the record entries cannot fit in the header, 95*cdf0e10cSrcweir * then nextRecordList has the local ID of a 96*cdf0e10cSrcweir * recordList that contains the next set of records. 97*cdf0e10cSrcweir * Palm UInt16. 98*cdf0e10cSrcweir */ 99*cdf0e10cSrcweir int numRecords = 0; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /** 102*cdf0e10cSrcweir * Read in the data for the pdb header. Need to 103*cdf0e10cSrcweir * preserve the unsigned value for some of the fields. 104*cdf0e10cSrcweir * 105*cdf0e10cSrcweir * @param di a DataInput object 106*cdf0e10cSrcweir * @throws IOException if I/O error occurs 107*cdf0e10cSrcweir */ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir public void read(DataInput in) throws IOException { 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir pdbName = new byte[PalmDB.NAME_LENGTH]; 112*cdf0e10cSrcweir in.readFully(pdbName); 113*cdf0e10cSrcweir attribute = in.readShort(); 114*cdf0e10cSrcweir version = in.readUnsignedShort(); 115*cdf0e10cSrcweir creationDate = ((long) in.readInt()) & 0xffffffffL; 116*cdf0e10cSrcweir modificationDate = ((long) in.readInt()) & 0xffffffffL; 117*cdf0e10cSrcweir lastBackupDate = ((long) in.readInt()) & 0xffffffffL; 118*cdf0e10cSrcweir modificationNumber = ((long) in.readInt()) & 0xffffffffL; 119*cdf0e10cSrcweir appInfoID = in.readInt(); 120*cdf0e10cSrcweir sortInfoID = in.readInt(); 121*cdf0e10cSrcweir creatorID = in.readInt(); 122*cdf0e10cSrcweir typeID = in.readInt(); 123*cdf0e10cSrcweir uniqueIDSeed = in.readInt(); 124*cdf0e10cSrcweir nextRecordListID = in.readInt(); 125*cdf0e10cSrcweir numRecords = in.readUnsignedShort(); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir /** 129*cdf0e10cSrcweir * Write out pdb header data. 130*cdf0e10cSrcweir * 131*cdf0e10cSrcweir * @param out a DataOut object 132*cdf0e10cSrcweir * @throws IOException if I/O error occurs 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir public void write(DataOutput out) throws IOException { 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir out.write(pdbName); 138*cdf0e10cSrcweir out.writeShort(attribute); 139*cdf0e10cSrcweir out.writeShort(version); 140*cdf0e10cSrcweir out.writeInt((int) creationDate); 141*cdf0e10cSrcweir out.writeInt((int) modificationDate); 142*cdf0e10cSrcweir out.writeInt((int) lastBackupDate); 143*cdf0e10cSrcweir out.writeInt((int) modificationNumber); 144*cdf0e10cSrcweir out.writeInt(appInfoID); 145*cdf0e10cSrcweir out.writeInt(sortInfoID); 146*cdf0e10cSrcweir out.writeInt(typeID); 147*cdf0e10cSrcweir out.writeInt(creatorID); 148*cdf0e10cSrcweir out.writeInt(uniqueIDSeed); 149*cdf0e10cSrcweir out.writeInt(nextRecordListID); 150*cdf0e10cSrcweir out.writeShort(numRecords); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154