|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.RandomAccessFile org.WeaselReader.PalmIO.PalmDB
public class PalmDB
Base class for reading Palm database files. PalmDB extends RandomAccessFile
because it needs the various readXXX methods, as in DataInputStream, but it
is also necessary to randomly seek which is not available in DataInputStream.
This class is useful for only the basic structure inherent in any Palm
database. New classes should extend this class to handle features/formats
specific to databases used by applications, such as the ZtxtDB class which
reads zTXT Palm databases (which are read by Weasel Reader and others).
The Palm database header is a packed structure of Big Endian values. Its
structure conforms to the following C struct definitions:
typedef struct {
UInt8 name[dmDBNameLength];
UInt16 attributes;
UInt16 version;
UInt32 creationDate;
UInt32 modificationDate;
UInt32 lastBackupDate;
UInt32 modificationNumber;
LocalID appInfoID;
LocalID sortInfoID;
UInt32 type;
UInt32 creator;
UInt32 uniqueIDSeed;
RecordListType recordList;
} DatabaseHdrType;
typedef struct {
LocalID nextRecordListID;
UInt16 numRecords;
UInt16 firstEntry;
} RecordListType;
typedef struct {
LocalID localChunkID;
UInt8 attributes;
UInt8 uniqueID[3];
} RecordEntryType;
All of these values are unsigned. A LocalID is a type of Palm OS pointer
which is equivalent to a UInt32. See the comments on the private fields of
this class for more information on what these values mean.
Field Summary | |
---|---|
private long |
applicationInfoIDPtr
Byte offset from beginning of the file to the appInfoArea block. |
private long |
creationTime
Creation time in seconds of the database. |
static int |
DB_FLAG_BACKUP
Set if the database should be backed up during the next sync procedure. |
static int |
DB_FLAG_DIRTY_APPINFO
Set if the appInfoArea has changed. |
static int |
DB_FLAG_NEWER_OKAY
Set if it is acceptable for a database with the same name but higher version number to be installed over this database. |
static int |
DB_FLAG_NO_COPY
Set if the device should not permit this database to be beamed or copied to another device. |
static int |
DB_FLAG_READ_ONLY
Database is read-only while in Palm memory. |
static int |
DB_FLAG_RESET_ON_INSTALL
Set if the device must be reset after this database has been installed. |
static int |
DB_HEADER_LENGTH
The length of a Palm OS database header up to and including the numRecords field. |
static int |
DB_NAME_LENGTH
The length of the database name field in the Palm OS database header. |
private long |
dbCreatorID
Palm OS database creator ID string. |
private java.lang.String |
dbName
The Palm database name. |
private long |
dbTypeID
Palm OS database type ID string. |
private int |
flags
Palm database flags. |
private long |
lastBackupTime
Time of the last database backup in seconds. |
private long |
modificationNumber
Database's modification number, defined by the application. |
private long |
modificationTime
Last modification time in seconds of the database. |
private long |
nextRecordListIDPtr
In memory a Palm database can have multiple record list structures, though in practice there is never more than one. |
private int |
numRecords
Number of records in this database. |
static int |
PALM_CTIME_OFFSET
This is the offset from the Palm OS epoch to the standard UNIX epoch. |
static short |
REC_FLAG_BUSY
On a device, it means the record is open for writing. |
static short |
REC_FLAG_DELETE
Set if the record has been marked for deletion. |
static short |
REC_FLAG_DIRTY
Set if the record has been modified and must be backed up during the next sync procedure. |
static short |
REC_FLAG_SECRET
If set, Record is marked as "secret" and some Palm apps can selectively hide secret records unless a password is entered. |
private java.util.Vector<java.lang.Integer> |
recordFlags
This array contains the attribute flags for each record in the database. |
private java.util.Vector<java.lang.Integer> |
recordIDs
This array contains the unique IDs for each record in the database. |
private java.util.Vector<java.lang.Long> |
recordOffsets
This array contains the byte offsets for the beginning of each record in this database. |
private long |
sortInfoIDPtr
Byte offset from beginning of the file to the sortInfoArea block. |
private long |
uniqueIDSeed
Used as the base index for the record LocalID values. |
private int |
version
Database version number, defined by the application. |
Constructor Summary | |
---|---|
PalmDB(java.io.File pdbFile)
Create a complete PalmDB object from the contents of the specified pdb file. |
Method Summary | |
---|---|
long |
getApplicationInfoIDPtr()
|
long |
getCreationTime()
|
long |
getDbCreatorID()
|
java.lang.String |
getDbName()
|
long |
getDbTypeID()
|
int |
getFlags()
|
long |
getLastBackupTime()
|
long |
getModificationNumber()
|
long |
getModificationTime()
|
long |
getNextRecordListIDPtr()
|
int |
getNumRecords()
|
java.util.Vector<java.lang.Integer> |
getRecordFlags()
|
java.util.Vector<java.lang.Integer> |
getRecordIDs()
|
java.util.Vector<java.lang.Long> |
getRecordOffsets()
|
long |
getSortInfoIDPtr()
|
long |
getUniqueIDSeed()
|
int |
getVersion()
|
static void |
main(java.lang.String[] args)
Useful for loading and testing the PalmDB class from the command line. |
private void |
readHeader()
Read in a Palm OS database header and set the appropriate fields with data from the header. |
byte[] |
readRecord(int recIndex)
Read the specified record and return it as a byte array. |
long |
readUInt32()
Read an unsigned 32 bit integer from the input stream and zero extend it to a long to not lose any precision. |
int |
readUniqueID()
Read a three byte record unique ID value and return it as an int value. |
java.lang.String |
toString()
Show something semi-useful for this Palm database when the object is printed. |
Methods inherited from class java.io.RandomAccessFile |
---|
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DB_FLAG_READ_ONLY
public static final int DB_FLAG_DIRTY_APPINFO
public static final int DB_FLAG_BACKUP
public static final int DB_FLAG_NEWER_OKAY
public static final int DB_FLAG_RESET_ON_INSTALL
public static final int DB_FLAG_NO_COPY
public static final short REC_FLAG_SECRET
public static final short REC_FLAG_BUSY
public static final short REC_FLAG_DIRTY
public static final short REC_FLAG_DELETE
public static final int DB_NAME_LENGTH
public static final int DB_HEADER_LENGTH
public static final int PALM_CTIME_OFFSET
private java.lang.String dbName
private int flags
private int version
private long creationTime
private long modificationTime
private long lastBackupTime
private long modificationNumber
private long applicationInfoIDPtr
private long sortInfoIDPtr
private long dbTypeID
private long dbCreatorID
private long uniqueIDSeed
private long nextRecordListIDPtr
private int numRecords
private java.util.Vector<java.lang.Long> recordOffsets
private java.util.Vector<java.lang.Integer> recordFlags
private java.util.Vector<java.lang.Integer> recordIDs
Constructor Detail |
---|
public PalmDB(java.io.File pdbFile) throws java.io.IOException
pdbFile
- an existing pdb file to load and parse into a PalmDB.
java.io.IOException
- if an error occurs while reading the header.Method Detail |
---|
public java.lang.String getDbName()
public int getFlags()
public int getVersion()
public long getCreationTime()
public long getModificationTime()
public long getLastBackupTime()
public long getModificationNumber()
public long getDbTypeID()
public long getDbCreatorID()
public long getUniqueIDSeed()
public int getNumRecords()
public long getApplicationInfoIDPtr()
public long getSortInfoIDPtr()
public long getNextRecordListIDPtr()
public java.util.Vector<java.lang.Long> getRecordOffsets()
public java.util.Vector<java.lang.Integer> getRecordFlags()
public java.util.Vector<java.lang.Integer> getRecordIDs()
public byte[] readRecord(int recIndex) throws java.io.IOException, java.lang.ArrayIndexOutOfBoundsException
recIndex
- the zero-based record index to read.
java.io.IOException
- if an I/O error occurs such as all bytes of a record
not being read in.
java.lang.ArrayIndexOutOfBoundsException
- if the requested record index does
not exist.public long readUInt32() throws java.io.IOException
java.io.IOException
- for any I/O error while reading the input stream.public int readUniqueID() throws java.io.IOException
java.io.IOException
- for any I/O error while reading the input stream.public java.lang.String toString()
toString
in class java.lang.Object
private void readHeader() throws java.io.IOException
java.io.IOException
- if an I/O error occurs while reading the header.public static void main(java.lang.String[] args)
args
- the first argument is the input filename, the second is an
optional boolean (0/1) toggling whether to print the record entry
array, and the third is an optional index of a record to print.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |