1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 package org.w3c.tidy;
55
56 import java.io.IOException;
57 import java.io.OutputStream;
58 import java.io.OutputStreamWriter;
59 import java.io.UnsupportedEncodingException;
60 import java.io.Writer;
61
62
63 /**
64 * Output implementation using java writers.
65 * @author Fabrizio Giustina
66 * @version $Revision: 807 $ ($Author: fgiust $)
67 */
68 public class OutJavaImpl implements Out
69 {
70
71 /**
72 * Java input stream writer.
73 */
74 private Writer writer;
75
76 /**
77 * Newline string.
78 */
79 private char[] newline;
80
81 /**
82 * Constructor.
83 * @param configuration actual configuration instance (needed for newline configuration)
84 * @param encoding encoding name
85 * @param out output stream
86 * @throws UnsupportedEncodingException if the undelining OutputStreamWriter doesn't support the rquested encoding.
87 */
88 protected OutJavaImpl(Configuration configuration, String encoding, OutputStream out)
89 throws UnsupportedEncodingException
90 {
91 this.writer = new OutputStreamWriter(out, encoding);
92 this.newline = configuration.newline;
93 }
94
95 /**
96 * Constructor.
97 * @param configuration actual configuration instance (needed for newline configuration)
98 * @param out Writer
99 */
100 protected OutJavaImpl(Configuration configuration, Writer out)
101 {
102 this.writer = out;
103 this.newline = configuration.newline;
104 }
105
106 /**
107 * @see org.w3c.tidy.Out#outc(int)
108 */
109 public void outc(int c)
110 {
111 try
112 {
113 writer.write(c);
114 }
115 catch (IOException e)
116 {
117
118 System.err.println("OutJavaImpl.outc: " + e.getMessage());
119 }
120 }
121
122 /**
123 * @see org.w3c.tidy.Out#outc(byte)
124 */
125 public void outc(byte c)
126 {
127 try
128 {
129 writer.write(c);
130 }
131 catch (IOException e)
132 {
133
134 System.err.println("OutJavaImpl.outc: " + e.getMessage());
135 }
136 }
137
138 /**
139 * @see org.w3c.tidy.Out#newline()
140 */
141 public void newline()
142 {
143 try
144 {
145 writer.write(this.newline);
146 }
147 catch (IOException e)
148 {
149
150 System.err.println("OutJavaImpl.newline: " + e.getMessage());
151 }
152 }
153
154 /**
155 * @see org.w3c.tidy.Out#flush()
156 */
157 public void flush()
158 {
159 try
160 {
161 writer.flush();
162 }
163 catch (IOException e)
164 {
165 System.err.println("OutJavaImpl.flush: " + e.getMessage());
166 }
167 }
168
169 }