Printer.java
5.67 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* Decompiled with CFR 0_118.
*/
package com.day.jcr.vault.util.xml.serialize;
import com.day.jcr.vault.util.xml.serialize.OutputFormat;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
public class Printer {
protected final OutputFormat _format;
protected Writer _writer;
protected StringWriter _dtdWriter;
protected Writer _docWriter;
protected IOException _exception;
private static final int BufferSize = 4096;
private final char[] _buffer = new char[4096];
private int _pos = 0;
public Printer(Writer writer, OutputFormat format) {
this._writer = writer;
this._format = format;
this._exception = null;
this._dtdWriter = null;
this._docWriter = null;
this._pos = 0;
}
public IOException getException() {
return this._exception;
}
public void enterDTD() throws IOException {
if (this._dtdWriter == null) {
this.flushLine(false);
this._dtdWriter = new StringWriter();
this._docWriter = this._writer;
this._writer = this._dtdWriter;
}
}
public String leaveDTD() throws IOException {
if (this._writer == this._dtdWriter) {
this.flushLine(false);
this._writer = this._docWriter;
return this._dtdWriter.toString();
}
return null;
}
public void printText(String text) throws IOException {
try {
int length = text.length();
for (int i = 0; i < length; ++i) {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
this._buffer[this._pos] = text.charAt(i);
++this._pos;
}
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void printText(StringBuffer text) throws IOException {
try {
int length = text.length();
for (int i = 0; i < length; ++i) {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
this._buffer[this._pos] = text.charAt(i);
++this._pos;
}
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void printText(char[] chars, int start, int length) throws IOException {
try {
while (length-- > 0) {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
this._buffer[this._pos] = chars[start];
++start;
++this._pos;
}
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void printText(char ch) throws IOException {
try {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
this._buffer[this._pos] = ch;
++this._pos;
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void printSpace() throws IOException {
try {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
this._buffer[this._pos] = 32;
++this._pos;
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void breakLine() throws IOException {
try {
if (this._pos == 4096) {
this._writer.write(this._buffer);
this._pos = 0;
}
String line = this._format.getLineSeparator();
char[] chL = line.toCharArray();
for (int i = 0; i < chL.length; ++i) {
this._buffer[this._pos++] = chL[i];
}
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
}
public void breakLine(boolean preserveSpace) throws IOException {
this.breakLine();
}
public void flushLine(boolean preserveSpace) throws IOException {
block2 : {
try {
this._writer.write(this._buffer, 0, this._pos);
}
catch (IOException except) {
if (this._exception != null) break block2;
this._exception = except;
}
}
this._pos = 0;
}
public void flush() throws IOException {
try {
this._writer.write(this._buffer, 0, this._pos);
this._writer.flush();
}
catch (IOException except) {
if (this._exception == null) {
this._exception = except;
}
throw except;
}
this._pos = 0;
}
public void indent() {
}
public void unindent() {
}
public int getNextIndent() {
return 0;
}
public void setNextIndent(int indent) {
}
public void setThisIndent(int indent) {
}
}