Class PalmDB

java.lang.Object
  |
  +--PalmDB

public class PalmDB
extends java.lang.Object

Converts between the Palm OS on-disk PRC format (used for applications and some data files) and a simple Java in-memory representation. With a slight effort, this could be extended to write and read PDB (the more common data format) as well.

The header fields are stored as publicly-accessible fields, along with a list of the records, each of which is stored as a PalmDB.PRCRecord. All the internals are visible, so be careful; this is quick and dirty, but it ain't rocket science anyway. Note especially that the records in a parsed file all initially share the same buffer of data. When modifying, replace it with a new buffer rather than overwriting other records' data!

Note: appInfo records and sortInfo records are ignored (with a warning) if present, and cannot be generated.

Used from the command line, reads a PRC file and dumps its entire contents to the console. This is equivalent to:

 	PalmDB db = load(new File(args[0]));
	System.out.println(db);
 

See http://www.palmos.com/ for more information on the file format.

TODO:
- Convert dates to and from a java date format (Calendar?)
- read and write appInfo and sortInfo records
- implement/test PDB support


Nested Class Summary
static class PalmDB.Resource
          Note: when parsing, each record has a pointer into the same block of data, so either treat it as read-only (in terms of length, at least), or replace it with your own byte array to modify it.
 
Field Summary
 int attributes
          Somewhat mysterious bits.
 int creationDate
          Seconds since 1/1/1904.
 java.lang.String creator
          A four-character String containing a unique, registered database creator code.
 int lastBackupDate
          Seconds since 1/1/1904.
 int modificationDate
          Seconds since 1/1/1904.
 int modificationNumber
          Related to syncing, perhaps?
 java.lang.String name
          The name given to the file when it is written.
 java.util.LinkedList records
          Contains the Resources that contain the database's contents.
 java.lang.String type
          A four-character String containing a unique, registered database type.
 int uniqueIDSeed
          Not used for PRC.
 int version
          A version field (encoding is application-specific?)
 
Constructor Summary
PalmDB()
           
 
Method Summary
static PalmDB load(java.io.File file)
          Reads a PRC file from the filesystem and parses its contents.
static void main(java.lang.String[] args)
          Loads the PRC file named by the first argument and dumps its contents.
static PalmDB parse(byte[] data)
          Breaks the elements of a PRC file into header and records for further processing.
 void save(java.io.File file)
          Write the contents of this PRCFile to the filesystem.
 java.lang.String toString()
           
 byte[] write()
          Captures the output of write(OutputStream) in a byte array, mostly for symmetry with the parsing side, and to simplify debugging.
 void write(java.io.OutputStream os)
          Writes the contents of this PRCFile to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public java.lang.String name
The name given to the file when it is written.


attributes

public int attributes
Somewhat mysterious bits. Apparently, 0x01 is the 'isPRC' bit.


version

public int version
A version field (encoding is application-specific?)


creationDate

public int creationDate
Seconds since 1/1/1904. TODO: parse to/from Java Date or Calendar


modificationDate

public int modificationDate
Seconds since 1/1/1904. TODO: parse to/from Java Date or Calendar


lastBackupDate

public int lastBackupDate
Seconds since 1/1/1904. TODO: parse to/from Java Date or Calendar


modificationNumber

public int modificationNumber
Related to syncing, perhaps?


type

public java.lang.String type
A four-character String containing a unique, registered database type.


creator

public java.lang.String creator
A four-character String containing a unique, registered database creator code.


uniqueIDSeed

public int uniqueIDSeed
Not used for PRC. Set to 0.


records

public java.util.LinkedList records
Contains the Resources that contain the database's contents.

Constructor Detail

PalmDB

public PalmDB()
Method Detail

main

public static void main(java.lang.String[] args)
Loads the PRC file named by the first argument and dumps its contents.


load

public static PalmDB load(java.io.File file)
                   throws java.io.IOException
Reads a PRC file from the filesystem and parses its contents.

java.io.IOException

parse

public static PalmDB parse(byte[] data)
Breaks the elements of a PRC file into header and records for further processing.

Parameters:
data - The unparsed contents of a PRC file.

write

public void write(java.io.OutputStream os)
           throws java.io.IOException
Writes the contents of this PRCFile to the given stream.

java.io.IOException

write

public byte[] write()
Captures the output of write(OutputStream) in a byte array, mostly for symmetry with the parsing side, and to simplify debugging.


save

public void save(java.io.File file)
          throws java.io.IOException
Write the contents of this PRCFile to the filesystem.

java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object