|
|||||||||
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 org.WeaselReader.PalmIO.ZtxtDB
public class ZtxtDB
This class supports reading a Weasel Reader zTXT database file. The
underlying Palm OS PDB structure is handled by PalmDB while this class
handles the data specific to the zTXT format. The ZtxtDB class represents the
zTXT format version 1.44 which is the final Weasel Reader for Palm OS zTXT
format. Any future zTXT format will not be contained within a Palm OS
database.
Limitations:
Nested Class Summary | |
---|---|
class |
ZtxtDB.Annotations
A collection of annotations. |
Field Summary | |
---|---|
private int |
annotationRecordIndex
The index of the record containing the annotation index. |
private ZtxtDB.Annotations |
annotations
The annotations for this zTXT document. |
private int |
bookmarkRecordIndex
The index of the record containing the bookmark list/index. |
private Bookmarks |
bookmarks
The bookmarks for this zTXT document. |
private long |
crc32
A CRC32 value computed over all of the uncompressed text data. |
private long |
dataSize
The total size of the text data when uncompressed. |
private java.util.zip.Inflater |
decompressor
The decompression information for this zTXT database. |
static int |
MAX_ANNOTATION_LENGTH
The maximum length of a zTXT annotation. |
static int |
MAX_TITLE_LENGTH
The maximum length of a zTXT bookmark or annotation title. |
private int |
numAnnotations
The number of annotations present in this zTXT document. |
private int |
numBookmarks
The number of bookmarks present in this zTXT document. |
private int |
numDataRecords
The number of text data records in this zTXT file. |
private int |
recordSize
The size of an uncompressed data record. |
static java.lang.String |
WEASEL_CREATOR_ID
Weasel Reader database creator ID. |
static java.lang.String |
WEASEL_TYPE_ID
Weasel Reader database type ID. |
static short |
ZTXT_NONUNIFORM
If this flag is set then not all data records in this zTXT will necessarily be of size recordSize but may be slightly different. |
static short |
ZTXT_RANDOMACCESS
If this flag is set, this zTXT supports random access of the compressed text records. |
static int |
ZTXT_VERSION
The highest zTXT format version recognized by this class. |
private short |
zTXTFlags
Flags to indicate features of this zTXT document. |
private int |
zTXTVersion
The zTXT format version for this document. |
Fields inherited from class org.WeaselReader.PalmIO.PalmDB |
---|
DB_FLAG_BACKUP, DB_FLAG_DIRTY_APPINFO, DB_FLAG_NEWER_OKAY, DB_FLAG_NO_COPY, DB_FLAG_READ_ONLY, DB_FLAG_RESET_ON_INSTALL, DB_HEADER_LENGTH, DB_NAME_LENGTH, PALM_CTIME_OFFSET, REC_FLAG_BUSY, REC_FLAG_DELETE, REC_FLAG_DIRTY, REC_FLAG_SECRET |
Constructor Summary | |
---|---|
ZtxtDB(java.io.File inputFile)
Create a new ZtxtDB and load the specified zTXT document. |
Method Summary | |
---|---|
long |
computeCRC32()
Compute a CRC32 value over the text data records in the database. |
void |
endDecompression()
End the decompression of data and clean up any data used by the Inflater object. |
protected void |
finalize()
Close any open resources before garbage collection. |
int |
getAnnotationRecordIndex()
|
ZtxtDB.Annotations |
getAnnotations()
|
int |
getBookmarkRecordIndex()
|
Bookmarks |
getBookmarks()
|
long |
getCRC32()
|
long |
getDataSize()
|
int |
getNumAnnotations()
|
int |
getNumBookmarks()
|
int |
getNumDataRecords()
|
int |
getRecordSize()
|
short |
getzTXTFlags()
|
int |
getzTXTVersion()
|
java.lang.String |
getzTXTVersionString()
Convert the two version bytes into a readable string. |
void |
initializeDecompression()
Initialize the decompression stream. |
static void |
main(java.lang.String[] args)
Prints values from the zTXT header and validates the CRC32 within the header. |
private void |
parseOffsetsAndTitles(byte[] data,
int numEntries,
int[] offsetArray,
java.lang.String[] titleArray)
Parse the offset/title data in a byte array that is common to both bookmark and annotation indices. |
private void |
readAnnotations()
Load the annotation index and annotation text blocks into memory. |
private void |
readBookmarks()
Load the bookmark array into memory for quicker access. |
java.lang.String |
readTextRecord(int index)
Read the specified text data record and decompress it. |
private void |
readzTXTHeader()
Read the zTXT header data from record zero. |
java.lang.String |
toString()
Show something semi-useful for this zTXT when the object is printed. |
boolean |
validateCRC32()
Validate the CRC32 stored in the zTXT header against the CRC32 computed over the text data records in the database. |
Methods inherited from class org.WeaselReader.PalmIO.PalmDB |
---|
getApplicationInfoIDPtr, getCreationTime, getDbCreatorID, getDbName, getDbTypeID, getFlags, getLastBackupTime, getModificationNumber, getModificationTime, getNextRecordListIDPtr, getNumRecords, getRecordFlags, getRecordIDs, getRecordOffsets, getSortInfoIDPtr, getUniqueIDSeed, getVersion, readRecord, readUInt32, readUniqueID |
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, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String WEASEL_CREATOR_ID
public static final java.lang.String WEASEL_TYPE_ID
public static final int MAX_TITLE_LENGTH
public static final int MAX_ANNOTATION_LENGTH
public static final int ZTXT_VERSION
public static final short ZTXT_RANDOMACCESS
public static final short ZTXT_NONUNIFORM
private int zTXTVersion
private int numDataRecords
private long dataSize
private int recordSize
private int numBookmarks
private int bookmarkRecordIndex
private int numAnnotations
private int annotationRecordIndex
private short zTXTFlags
private long crc32
private Bookmarks bookmarks
private ZtxtDB.Annotations annotations
private java.util.zip.Inflater decompressor
Constructor Detail |
---|
public ZtxtDB(java.io.File inputFile) throws java.io.IOException, java.util.zip.DataFormatException
inputFile
- a zTXT document database to read from disk.
java.io.IOException
- if an I/O error occurs while reading the PDB header or
the zTXT header.
java.util.zip.DataFormatException
- if the input file is not a zTXT database (its
typeID is not 'zTXT')Method Detail |
---|
public int getRecordSize()
public short getzTXTFlags()
public int getzTXTVersion()
public java.lang.String getzTXTVersionString()
public int getNumDataRecords()
public long getDataSize()
public int getNumBookmarks()
public int getBookmarkRecordIndex()
public int getNumAnnotations()
public int getAnnotationRecordIndex()
public long getCRC32()
public Bookmarks getBookmarks()
public ZtxtDB.Annotations getAnnotations()
public boolean validateCRC32()
public long computeCRC32() throws java.io.IOException
java.io.IOException
- if an I/O error occurred while computing the CRC32
value.public void initializeDecompression() throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException, java.util.zip.DataFormatException
java.io.IOException
- if an I/O error occurs while reading the first record.
java.lang.ArrayIndexOutOfBoundsException
- if the first text record does not
exist.
java.util.zip.DataFormatException
- if the zLib formatted data in the input text
record is invalid.public void endDecompression()
public java.lang.String readTextRecord(int index) throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException, java.util.zip.DataFormatException
index
- the index of the text data record to be read, counting from
zero.
java.io.IOException
- if an I/O error occurs while reading the requested
record.
java.lang.ArrayIndexOutOfBoundsException
- if the requested record index does
not exist.
java.util.zip.DataFormatException
- if the Inflater is not initialized or if the
zLib formatted data in the input text record is invalid.public java.lang.String toString()
toString
in class PalmDB
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
private void readzTXTHeader() throws java.io.IOException
java.io.IOException
- if an I/O error occurs while reading from the database.private void readBookmarks() throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException
java.io.IOException
- if an I/O error occurs reading the bookmark record.
java.lang.ArrayIndexOutOfBoundsException
- if the bookmark record is listed
as existing but cannot be found.private void readAnnotations() throws java.lang.ArrayIndexOutOfBoundsException, java.io.IOException
java.io.IOException
- if an I/O error occurs reading the annotation index
record.
java.lang.ArrayIndexOutOfBoundsException
- if the annotation index record is
listed as existing but cannot be found.private void parseOffsetsAndTitles(byte[] data, int numEntries, int[] offsetArray, java.lang.String[] titleArray) throws java.io.IOException
data
- the array of data bytes to be parsed.numEntries
- the number of offsets/titles to be parsed from the data
array.offsetArray
- an empty allocated array where byte offset values will
be stored.titleArray
- an empty allocated array where titles will be stored.
java.io.IOException
- if the input data array is too small which likely means
some sort of I/O error when the array was read.public static void main(java.lang.String[] args)
args
- the first argument is the input filename, the second argument
is an optional boolean (0/1) toggling whether to print the
bookmark list, the third argument is an optional boolean (0/1)
toggling whether to print the annotation list, the fourth
argument is an option annotation number to print the full text
of, and the fifth argument is the number of a text record to
decompress and print.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |