KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > etymon > pj > object > BaseObject


1 package com.etymon.pj.object;
2
3 import java.io.*;
4 import java.util.*;
5 import com.etymon.pj.*;
6
7 /**
8    The base class for all high level objects and page markings.
9    @author Nassib Nassar
10 */

11 public abstract class BaseObject
12     implements Cloneable JavaDoc {
13
14     /**
15        Returns a deep copy of this object.
16        @return a deep copy of this object.
17        @exception CloneNotSupportedException if the instance can not be cloned.
18     */

19     public abstract Object JavaDoc clone() throws CloneNotSupportedException JavaDoc;
20     
21     /**
22        Writes this object to a file in PDF format.
23        @param raf the file to write to.
24        @return the number of bytes written.
25        @exception IOException if an I/O error occurs.
26      */

27     public abstract long writePdf(OutputStream os) throws
28         IOException;
29
30     /**
31        Writes a char to a stream.
32        @param os the stream to write to.
33        @param c the character to write.
34        @return the number of bytes written.
35        @exception IOException if an I/O error occurs.
36     */

37     public static long write(OutputStream os, char c)
38         throws IOException {
39         os.write((int)c);
40         return 1;
41     }
42     
43     /**
44        Writes a byte[] to a stream.
45        @param os the stream to write to.
46        @param b the byte[] to write.
47        @return the number of bytes written.
48        @exception IOException if an I/O error occurs.
49     */

50     public static long write(OutputStream os, byte[] b)
51         throws IOException {
52         os.write(b);
53         return b.length;
54     }
55     
56     /**
57        Writes an Object to a stream.
58        @param os the stream to write to.
59        @param obj the Object to write.
60        @return the number of bytes written.
61        @exception IOException if an I/O error occurs.
62     */

63     public static long write(OutputStream os, Object JavaDoc obj)
64         throws IOException {
65         return write(os, obj.toString().getBytes());
66     }
67
68     /**
69        Writes an Object to a stream followed by a carriage return.
70        @param os the stream to write to.
71        @param obj the Object to write.
72        @return the number of bytes written.
73        @exception IOException if an I/O error occurs.
74     */

75     public static long writeln(OutputStream os, Object JavaDoc obj)
76         throws IOException {
77         return write(os, obj) + write(os, PjConst.PDF_EOL);
78     }
79
80     /**
81        Returns a string representation of this object in PDF format.
82        @return the string representation.
83      */

84     public String JavaDoc toString() {
85         ByteArrayOutputStream baos = new ByteArrayOutputStream();
86         try {
87             writePdf(baos);
88         }
89         catch (IOException e) {
90             return null;
91         }
92         return baos.toString();
93     }
94
95 }
96
Popular Tags