SimpleCharStream.java
12.1 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.formcalc;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
public class SimpleCharStream {
public static final boolean staticFlag = false;
int bufsize;
int available;
int tokenBegin;
public int bufpos = -1;
protected int[] bufline;
protected int[] bufcolumn;
protected int column = 0;
protected int line = 1;
protected boolean prevCharIsCR = false;
protected boolean prevCharIsLF = false;
protected Reader inputStream;
protected char[] buffer;
protected int maxNextCharInd = 0;
protected int inBuf = 0;
protected int tabSize = 8;
protected void setTabSize(int i) {
this.tabSize = i;
}
protected int getTabSize(int i) {
return this.tabSize;
}
protected void ExpandBuff(boolean wrapAround) {
char[] newbuffer = new char[this.bufsize + 2048];
int[] newbufline = new int[this.bufsize + 2048];
int[] newbufcolumn = new int[this.bufsize + 2048];
try {
if (wrapAround) {
System.arraycopy(this.buffer, this.tokenBegin, newbuffer, 0, this.bufsize - this.tokenBegin);
System.arraycopy(this.buffer, 0, newbuffer, this.bufsize - this.tokenBegin, this.bufpos);
this.buffer = newbuffer;
System.arraycopy(this.bufline, this.tokenBegin, newbufline, 0, this.bufsize - this.tokenBegin);
System.arraycopy(this.bufline, 0, newbufline, this.bufsize - this.tokenBegin, this.bufpos);
this.bufline = newbufline;
System.arraycopy(this.bufcolumn, this.tokenBegin, newbufcolumn, 0, this.bufsize - this.tokenBegin);
System.arraycopy(this.bufcolumn, 0, newbufcolumn, this.bufsize - this.tokenBegin, this.bufpos);
this.bufcolumn = newbufcolumn;
this.maxNextCharInd = this.bufpos += this.bufsize - this.tokenBegin;
} else {
System.arraycopy(this.buffer, this.tokenBegin, newbuffer, 0, this.bufsize - this.tokenBegin);
this.buffer = newbuffer;
System.arraycopy(this.bufline, this.tokenBegin, newbufline, 0, this.bufsize - this.tokenBegin);
this.bufline = newbufline;
System.arraycopy(this.bufcolumn, this.tokenBegin, newbufcolumn, 0, this.bufsize - this.tokenBegin);
this.bufcolumn = newbufcolumn;
this.maxNextCharInd = this.bufpos -= this.tokenBegin;
}
}
catch (Throwable t) {
throw new Error(t.getMessage());
}
this.bufsize += 2048;
this.available = this.bufsize;
this.tokenBegin = 0;
}
protected void FillBuff() throws IOException {
if (this.maxNextCharInd == this.available) {
if (this.available == this.bufsize) {
if (this.tokenBegin > 2048) {
this.maxNextCharInd = 0;
this.bufpos = 0;
this.available = this.tokenBegin;
} else if (this.tokenBegin < 0) {
this.maxNextCharInd = 0;
this.bufpos = 0;
} else {
this.ExpandBuff(false);
}
} else if (this.available > this.tokenBegin) {
this.available = this.bufsize;
} else if (this.tokenBegin - this.available < 2048) {
this.ExpandBuff(true);
} else {
this.available = this.tokenBegin;
}
}
try {
int i = this.inputStream.read(this.buffer, this.maxNextCharInd, this.available - this.maxNextCharInd);
if (i == -1) {
this.inputStream.close();
throw new IOException();
}
this.maxNextCharInd += i;
return;
}
catch (IOException e) {
--this.bufpos;
this.backup(0);
if (this.tokenBegin == -1) {
this.tokenBegin = this.bufpos;
}
throw e;
}
}
public char BeginToken() throws IOException {
this.tokenBegin = -1;
char c = this.readChar();
this.tokenBegin = this.bufpos;
return c;
}
protected void UpdateLineColumn(char c) {
++this.column;
if (this.prevCharIsLF) {
this.prevCharIsLF = false;
this.column = 1;
++this.line;
} else if (this.prevCharIsCR) {
this.prevCharIsCR = false;
if (c == '\n') {
this.prevCharIsLF = true;
} else {
this.column = 1;
++this.line;
}
}
switch (c) {
case '\r': {
this.prevCharIsCR = true;
break;
}
case '\n': {
this.prevCharIsLF = true;
break;
}
case '\t': {
--this.column;
this.column += this.tabSize - this.column % this.tabSize;
break;
}
}
this.bufline[this.bufpos] = this.line;
this.bufcolumn[this.bufpos] = this.column;
}
public char readChar() throws IOException {
if (this.inBuf > 0) {
--this.inBuf;
if (++this.bufpos == this.bufsize) {
this.bufpos = 0;
}
return this.buffer[this.bufpos];
}
if (++this.bufpos >= this.maxNextCharInd) {
this.FillBuff();
}
char c = this.buffer[this.bufpos];
this.UpdateLineColumn(c);
return c;
}
public int getColumn() {
return this.bufcolumn[this.bufpos];
}
public int getLine() {
return this.bufline[this.bufpos];
}
public int getEndColumn() {
return this.bufcolumn[this.bufpos];
}
public int getEndLine() {
return this.bufline[this.bufpos];
}
public int getBeginColumn() {
return this.bufcolumn[this.tokenBegin];
}
public int getBeginLine() {
return this.bufline[this.tokenBegin];
}
public void backup(int amount) {
this.inBuf += amount;
if ((this.bufpos -= amount) < 0) {
this.bufpos += this.bufsize;
}
}
public SimpleCharStream(Reader dstream, int startline, int startcolumn, int buffersize) {
this.inputStream = dstream;
this.line = startline;
this.column = startcolumn - 1;
this.available = this.bufsize = buffersize;
this.buffer = new char[buffersize];
this.bufline = new int[buffersize];
this.bufcolumn = new int[buffersize];
}
public SimpleCharStream(Reader dstream, int startline, int startcolumn) {
this(dstream, startline, startcolumn, 4096);
}
public SimpleCharStream(Reader dstream) {
this(dstream, 1, 1, 4096);
}
public void ReInit(Reader dstream, int startline, int startcolumn, int buffersize) {
this.inputStream = dstream;
this.line = startline;
this.column = startcolumn - 1;
if (this.buffer == null || buffersize != this.buffer.length) {
this.available = this.bufsize = buffersize;
this.buffer = new char[buffersize];
this.bufline = new int[buffersize];
this.bufcolumn = new int[buffersize];
}
this.prevCharIsCR = false;
this.prevCharIsLF = false;
this.maxNextCharInd = 0;
this.inBuf = 0;
this.tokenBegin = 0;
this.bufpos = -1;
}
public void ReInit(Reader dstream, int startline, int startcolumn) {
this.ReInit(dstream, startline, startcolumn, 4096);
}
public void ReInit(Reader dstream) {
this.ReInit(dstream, 1, 1, 4096);
}
public SimpleCharStream(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws UnsupportedEncodingException {
this(encoding == null ? new InputStreamReader(dstream) : new InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
public SimpleCharStream(InputStream dstream, int startline, int startcolumn, int buffersize) {
this(new InputStreamReader(dstream), startline, startcolumn, buffersize);
}
public SimpleCharStream(InputStream dstream, String encoding, int startline, int startcolumn) throws UnsupportedEncodingException {
this(dstream, encoding, startline, startcolumn, 4096);
}
public SimpleCharStream(InputStream dstream, int startline, int startcolumn) {
this(dstream, startline, startcolumn, 4096);
}
public SimpleCharStream(InputStream dstream, String encoding) throws UnsupportedEncodingException {
this(dstream, encoding, 1, 1, 4096);
}
public SimpleCharStream(InputStream dstream) {
this(dstream, 1, 1, 4096);
}
public void ReInit(InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws UnsupportedEncodingException {
this.ReInit(encoding == null ? new InputStreamReader(dstream) : new InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
public void ReInit(InputStream dstream, int startline, int startcolumn, int buffersize) {
this.ReInit(new InputStreamReader(dstream), startline, startcolumn, buffersize);
}
public void ReInit(InputStream dstream, String encoding) throws UnsupportedEncodingException {
this.ReInit(dstream, encoding, 1, 1, 4096);
}
public void ReInit(InputStream dstream) {
this.ReInit(dstream, 1, 1, 4096);
}
public void ReInit(InputStream dstream, String encoding, int startline, int startcolumn) throws UnsupportedEncodingException {
this.ReInit(dstream, encoding, startline, startcolumn, 4096);
}
public void ReInit(InputStream dstream, int startline, int startcolumn) {
this.ReInit(dstream, startline, startcolumn, 4096);
}
public String GetImage() {
if (this.bufpos >= this.tokenBegin) {
return new String(this.buffer, this.tokenBegin, this.bufpos - this.tokenBegin + 1);
}
return new String(this.buffer, this.tokenBegin, this.bufsize - this.tokenBegin) + new String(this.buffer, 0, this.bufpos + 1);
}
public char[] GetSuffix(int len) {
char[] ret = new char[len];
if (this.bufpos + 1 >= len) {
System.arraycopy(this.buffer, this.bufpos - len + 1, ret, 0, len);
} else {
System.arraycopy(this.buffer, this.bufsize - (len - this.bufpos - 1), ret, 0, len - this.bufpos - 1);
System.arraycopy(this.buffer, 0, ret, len - this.bufpos - 1, this.bufpos + 1);
}
return ret;
}
public void Done() {
this.buffer = null;
this.bufline = null;
this.bufcolumn = null;
}
public void adjustBeginLineColumn(int newLine, int newCol) {
int i;
int start = this.tokenBegin;
int len = this.bufpos >= this.tokenBegin ? this.bufpos - this.tokenBegin + this.inBuf + 1 : this.bufsize - this.tokenBegin + this.bufpos + 1 + this.inBuf;
int j = 0;
int k = 0;
int nextColDiff = 0;
int columnDiff = 0;
for (i = 0; i < len; ++i) {
j = start % this.bufsize;
if (this.bufline[j] != this.bufline[k = ++start % this.bufsize]) break;
this.bufline[j] = newLine;
nextColDiff = columnDiff + this.bufcolumn[k] - this.bufcolumn[j];
this.bufcolumn[j] = newCol + columnDiff;
columnDiff = nextColDiff;
}
if (i < len) {
this.bufline[j] = newLine++;
this.bufcolumn[j] = newCol + columnDiff;
while (i++ < len) {
j = start % this.bufsize;
if (this.bufline[j] != this.bufline[++start % this.bufsize]) {
this.bufline[j] = newLine++;
continue;
}
this.bufline[j] = newLine;
}
}
this.line = this.bufline[j];
this.column = this.bufcolumn[j];
}
}