KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > etymon > pjx > PdfReference


1 /*
2   Copyright (C) Etymon Systems, Inc. <http://www.etymon.com/>
3 */

4
5 package com.etymon.pjx;
6
7 import java.io.*;
8
9 /**
10    Represents the PDF indirect reference.
11    @author Nassib Nassar
12 */

13 public class PdfReference
14     extends PdfObject {
15
16     /**
17        The generation number of this indirect reference.
18     */

19     protected int _g;
20
21     /**
22        The object number of this indirect reference.
23      */

24     protected int _n;
25
26     /**
27        Constructs an indirect reference representing a specified
28        object number and generation number.
29        @param n the object number.
30        @param g the generation number.
31      */

32     public PdfReference(int n, int g) {
33         _n = n;
34         _g = g;
35     }
36
37     public boolean equals(Object JavaDoc obj) {
38
39         if ( (obj == null) || ( !(obj instanceof PdfReference) ) ) {
40             return false;
41         }
42
43         PdfReference r = (PdfReference)obj;
44         return ( (_n == r._n) && (_g == r._g) );
45     }
46
47     /**
48        Returns the generation number of this indirect reference.
49        @return the generation number.
50      */

51     public int getGenerationNumber() {
52         return _g;
53     }
54
55     /**
56        Returns the object number of this indirect reference.
57        @return the object number.
58      */

59     public int getObjectNumber() {
60         return _n;
61     }
62
63     public int hashCode() {
64         return _n + (_g << 16);
65     }
66
67     protected int writePdf(PdfWriter w, boolean spacing) throws IOException {
68
69         DataOutputStream dos = w.getDataOutputStream();
70
71         int count;
72         
73         if (spacing) {
74             dos.write(' ');
75             count = 1;
76         } else {
77             count = 0;
78         }
79         
80         String JavaDoc s = Integer.toString(_n);
81         dos.writeBytes(s);
82         count += s.length();
83
84         dos.write(' ');
85         count++;
86
87         s = Integer.toString(_g);
88         dos.writeBytes(s);
89         count += s.length();
90
91         dos.writeBytes(" R");
92         return count + 2;
93
94     }
95
96 }
97
Popular Tags