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 / BookMark.java < prev    next >
Encoding:
Java Source  |  1999-05-26  |  1.6 KB  |  78 lines

  1. import java.io.*;
  2.  
  3. /**
  4.  * <code>BookMark</code> class is used to read/write PilotDoc bookmark records
  5.  * @author Jeffrey A. Krzysztow
  6.  * @author Pat Beirne
  7.  * @version 1.1
  8.  */
  9. public class BookMark {
  10.     /**
  11.      * the name of the bookmark
  12.      * @since 1.0
  13.      */
  14.     public String name = "";     // 16 Bytes    Bookmark name
  15.  
  16.     /**
  17.      * offset into PilotDoc for this bookmark
  18.      * @since 1.0
  19.      */
  20.     public int fileOffset = -1;    // 4 DWord    file offset
  21.                                 // 20 bytes bookmark
  22.  
  23.     /**
  24.      * The size of the BookMark in bytes
  25.      * @returns the number of bytes in the BookMark
  26.      * @since 1.0
  27.      */
  28.     public static int getSize() {
  29.         return(20);
  30.     }
  31.  
  32.     /**
  33.      * Reads the BookMark from the DataInput
  34.      * @param the DataInput to read from
  35.      * @since 1.0
  36.      */
  37.     public void read(DataInput di) throws IOException {
  38.         byte[] b = new byte[16];
  39.         di.readFully(b);
  40.         name = new String(b);
  41.         int i = name.indexOf('\0');
  42.         if(i >= 0) {
  43.             name = name.substring(0, i);
  44.         }
  45.         fileOffset = di.readInt();
  46.     }
  47.  
  48.     /**
  49.      * Writes the BookMark to the DataInput
  50.      * @param the DataInput to write to
  51.      * @since 1.0
  52.      */
  53.     public void write(DataOutput out) throws IOException {
  54.         byte[] b = new byte[16];
  55.         byte[] bName = name.getBytes();
  56.         for(int x=0; x < b.length; x++) {
  57.             if(x < bName.length) {
  58.                 b[x] = bName[x];
  59.             }
  60.             else {
  61.                 b[x] = 0;
  62.             }
  63.         }
  64.         out.write(b);
  65.         out.writeInt(fileOffset);
  66.     }
  67.  
  68.     /**
  69.      * override Object.toString()
  70.      * @since 1.0
  71.      */
  72.     public String toString() {
  73.         return ">> BookMark <<\nname = `" + name
  74.             + "`\nfileOffset = " + fileOffset;
  75.     }
  76. }
  77.  
  78.