org.WeaselReader.PalmIO
Class Utility

java.lang.Object
  extended by org.WeaselReader.PalmIO.Utility

public class Utility
extends java.lang.Object

A class of utility methods primarily focused on manipulating data within Palm OS database files. There are methods for converting Palm ID values, Palm date values, reading/writing unsigned 32bit int values, and pretty-printing a byte array.

Version:
$Id$
Author:
John Gruenenfelder

Constructor Summary
Utility()
           
 
Method Summary
static long fromUInt32(byte[] buf, int i)
          Convert an unsigned 32 bit value (UInt32) to a long without losing the original unsigned value.
static java.lang.String idToString(long id)
          Convert a Palm OS database 'ID' from a four byte value to a four character String so it can be printed.
static void printDataBlock(java.io.PrintStream out, int bytesPerLine, byte[] data, int startOffset, int length, long address)
          Output a block of data in mixed hex/ASCII format.
static long stringToID(java.lang.String id)
          Convert a String representation of a Palm OS database 'ID' back into a standard four byte literal value.
static long toPalmEpoch(java.util.Date time)
          Convert a Java Date (which uses the standard UNIX time epoch) into a seconds count in the Palm epoch suitable for use in any of the time fields in the PalmDB class.
static void toUInt32(long val, byte[] buf, int i)
          Put an unsigned 32 bit value stored in a long into a byte array at the specified index.
static java.util.Date toUNIXEpoch(long palmTime)
          Convert a Palm OS date (a long count of seconds) from the Palm OS epoch to a Date in the standard UNIX epoch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utility

public Utility()
Method Detail

idToString

public static java.lang.String idToString(long id)
Convert a Palm OS database 'ID' from a four byte value to a four character String so it can be printed. Use this to get a usable String from dbTypeID or dbCreatorID.

Parameters:
id - the ID value to be converted.
Returns:
a String representation of the given Palm database ID.

stringToID

public static long stringToID(java.lang.String id)
Convert a String representation of a Palm OS database 'ID' back into a standard four byte literal value.

Parameters:
id - the ID String to convert.
Returns:
a four byte literal ID stored in a long.

fromUInt32

public static long fromUInt32(byte[] buf,
                              int i)
Convert an unsigned 32 bit value (UInt32) to a long without losing the original unsigned value.

Parameters:
buf - the array containing the value to be converted.
i - the index of the array element to be converted.
Returns:
a converted UInt32 value stored in a long.

toUInt32

public static void toUInt32(long val,
                            byte[] buf,
                            int i)
Put an unsigned 32 bit value stored in a long into a byte array at the specified index.

Parameters:
val - a long containing a UInt32 value to be stored.
buf - the byte array in which to store the UInt32 value.
i - the index of the array element to store the new value in.

toPalmEpoch

public static long toPalmEpoch(java.util.Date time)
Convert a Java Date (which uses the standard UNIX time epoch) into a seconds count in the Palm epoch suitable for use in any of the time fields in the PalmDB class.
The Palm epoch is the same as the original Macintosh epoch
   January 1, 1904 00:00:00 GMT
while the standard UNIX epoch is
   January 1, 1970 00:00:00 GMT

Parameters:
time - a point in time represented by a Java Date object.
Returns:
the time parameter converted into a count of seconds from the standard Palm OS epoch.

toUNIXEpoch

public static java.util.Date toUNIXEpoch(long palmTime)
Convert a Palm OS date (a long count of seconds) from the Palm OS epoch to a Date in the standard UNIX epoch.

Parameters:
palmTime - a point in time expressed as a seconds count in the Palm OS epoch.
Returns:
a Java Date object with the time converted to the UNIX epoch.

printDataBlock

public static void printDataBlock(java.io.PrintStream out,
                                  int bytesPerLine,
                                  byte[] data,
                                  int startOffset,
                                  int length,
                                  long address)
Output a block of data in mixed hex/ASCII format. Each line begins with the address offset for that particular line of data, followed by 16 data bytes output in hex, followed by those same bytes output in ASCII if the byte represents a printable character, otherwise a period is output. This format was borrowed from the ncurses tool 'hexedit'.

Parameters:
out - the stream to output to, such as System.out for standard output.
bytesPerLine - the number of data bytes to print per line. This value will be rounded down to a multiple of four.
data - the byte array containing the data to be printed.
startOffset - the offset in the data array at which to begin.
length - the number of bytes from the data array to print.
address - the memory address this block of data represents. Or, just pass 0 for it to count from the beginning of the startOffset. This is only for readability and convenience and has no effect on how the data is output.