home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils text / MakeDocJ 3.3 / MakeDocJ.exe / Source / DocumentHeader.java < prev    next >
Encoding:
Java Source  |  2000-05-23  |  3.3 KB  |  144 lines

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