home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils text / ReadDocJ 1.1 / ReadDocJ.exe / Source / DocumentHeader.java < prev    next >
Encoding:
Java Source  |  1999-05-26  |  2.8 KB  |  128 lines

  1. import java.io.*;
  2.  
  3. /**
  4.  * <code>DocumentHeader</code> class is used to read/write PilotDoc header records
  5.  * NOTE: Information about the various fields was taken from <a href="http://www.concentric.net/~n9mtb/cq/doc/format.html">CQ Codeworks</a>
  6.  * @author Jeffrey A. Krzysztow
  7.  * @author Pat Beirne
  8.  * @version 1.1
  9.  */
  10. public class DocumentHeader {
  11.     /**
  12.      * constant to indicate PilotDoc is uncompressed
  13.      * @since 1.0
  14.      */
  15.     public final static short UNCOMPRESSED = 1;
  16.  
  17.     /**
  18.      * constant to indicate PilotDoc is compressed
  19.      * @since 1.0
  20.      */
  21.     public final static short COMPRESSED = 2;
  22.  
  23.     /**
  24.      * size of text record
  25.      * @since 1.0
  26.      */
  27.     public final static short textRecordSize = 4096;
  28.  
  29.     /**
  30.      * version of PilotDoc
  31.      * @since 1.0
  32.      */
  33.     public short version = 0;                    // 2 Word    1=plain text, 2=compressed
  34.  
  35.     /**
  36.      * spare (unknown)
  37.      * @since 1.0
  38.      */
  39.     public short spare = 0;                        // 2 Word
  40.  
  41.     /**
  42.      * length of uncompressed PilotDoc
  43.      * @since 1.0
  44.      */
  45.     public int storyLen = 0;                    // 4 DWord    in bytes, when decompressed
  46.  
  47.     /**
  48.      * number of PilotDoc records
  49.      * @since 1.0
  50.      */
  51.     public short numRecords = 0;                // 2 Word    text records
  52.  
  53.     /**
  54.      * uncompressed text record size
  55.      * @since 1.0
  56.      */
  57.     public short recordSize = textRecordSize;    // 2 Word    usually 0x1000
  58.  
  59.     /**
  60.      * currently viewed position in the document
  61.      * not used by all readers
  62.      * @since 1.0
  63.      */
  64.     public int position = 0;                    // 4 DWord
  65.                                                 // 16 bytes for Document Header
  66.  
  67.     /**
  68.      * The size of the DocumentHeader in bytes
  69.      * @returns the number of bytes in the DocumentHeader
  70.      * @since 1.0
  71.      */
  72.     public static int getSize() {
  73.         return(16);
  74.     }
  75.  
  76.     /**
  77.      * Reads the DocumentHeader from the DataInput
  78.      * @param the DataInput to read from
  79.      * @since 1.0
  80.      */
  81.     public void read(DataInput di) throws IOException {
  82.         version = di.readShort();
  83.         spare = di.readShort();
  84.         storyLen = di.readInt();
  85.         numRecords = di.readShort();
  86.         recordSize = di.readShort();
  87.         position = di.readInt();
  88.     }
  89.  
  90.     /**
  91.      * Writes the DocumentHeader to the DataInput
  92.      * @param the DataInput to write to
  93.      * @since 1.0
  94.      */
  95.     public void write(DataOutput out) throws IOException {
  96.         out.writeShort(version);
  97.         out.writeShort(spare);
  98.         out.writeInt(storyLen);
  99.         out.writeShort(numRecords);
  100.         out.writeShort(recordSize);
  101.         out.writeInt(position);
  102.     }
  103.  
  104.     /**
  105.      * indicates whether the document is compressed or not
  106.      * @since 1.1
  107.      */
  108.     public boolean isCompressed() {
  109.         return version == COMPRESSED;
  110.     }
  111.  
  112.     /**
  113.      * override Object.toString()
  114.      * @since 1.0
  115.      */
  116.     public String toString() {
  117.         return ">> DocumentHeader <<"
  118.             + "\nversion = " + version
  119.             + "\nspare = " + spare
  120.             + "\nstoryLen = " + storyLen
  121.             + "\nnumRecords = " + numRecords
  122.             + "\nRecSize = " + recordSize
  123.             + "\nposition = " + position;
  124.     }
  125.  
  126. }
  127.  
  128.