1 | |
|
2 | |
|
3 | |
package org.apache.maven.surefire.group.parse; |
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
public class SimpleCharStream |
11 | |
{ |
12 | |
|
13 | |
public static final boolean staticFlag = false; |
14 | |
int bufsize; |
15 | |
int available; |
16 | |
int tokenBegin; |
17 | |
|
18 | 11 | public int bufpos = -1; |
19 | |
protected int bufline[]; |
20 | |
protected int bufcolumn[]; |
21 | |
|
22 | 11 | protected int column = 0; |
23 | 11 | protected int line = 1; |
24 | |
|
25 | 11 | protected boolean prevCharIsCR = false; |
26 | 11 | protected boolean prevCharIsLF = false; |
27 | |
|
28 | |
protected java.io.Reader inputStream; |
29 | |
|
30 | |
protected char[] buffer; |
31 | 11 | protected int maxNextCharInd = 0; |
32 | 11 | protected int inBuf = 0; |
33 | 11 | protected int tabSize = 8; |
34 | |
|
35 | 0 | protected void setTabSize(int i) { tabSize = i; } |
36 | 0 | protected int getTabSize(int i) { return tabSize; } |
37 | |
|
38 | |
|
39 | |
protected void ExpandBuff(boolean wrapAround) |
40 | |
{ |
41 | 0 | char[] newbuffer = new char[bufsize + 2048]; |
42 | 0 | int newbufline[] = new int[bufsize + 2048]; |
43 | 0 | int newbufcolumn[] = new int[bufsize + 2048]; |
44 | |
|
45 | |
try |
46 | |
{ |
47 | 0 | if (wrapAround) |
48 | |
{ |
49 | 0 | System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); |
50 | 0 | System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); |
51 | 0 | buffer = newbuffer; |
52 | |
|
53 | 0 | System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); |
54 | 0 | System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); |
55 | 0 | bufline = newbufline; |
56 | |
|
57 | 0 | System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); |
58 | 0 | System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); |
59 | 0 | bufcolumn = newbufcolumn; |
60 | |
|
61 | 0 | maxNextCharInd = (bufpos += (bufsize - tokenBegin)); |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); |
66 | 0 | buffer = newbuffer; |
67 | |
|
68 | 0 | System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); |
69 | 0 | bufline = newbufline; |
70 | |
|
71 | 0 | System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); |
72 | 0 | bufcolumn = newbufcolumn; |
73 | |
|
74 | 0 | maxNextCharInd = (bufpos -= tokenBegin); |
75 | |
} |
76 | |
} |
77 | 0 | catch (Throwable t) |
78 | |
{ |
79 | 0 | throw new Error(t.getMessage()); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | 0 | bufsize += 2048; |
84 | 0 | available = bufsize; |
85 | 0 | tokenBegin = 0; |
86 | 0 | } |
87 | |
|
88 | |
protected void FillBuff() throws java.io.IOException |
89 | |
{ |
90 | 25 | if (maxNextCharInd == available) |
91 | |
{ |
92 | 0 | if (available == bufsize) |
93 | |
{ |
94 | 0 | if (tokenBegin > 2048) |
95 | |
{ |
96 | 0 | bufpos = maxNextCharInd = 0; |
97 | 0 | available = tokenBegin; |
98 | |
} |
99 | 0 | else if (tokenBegin < 0) |
100 | 0 | bufpos = maxNextCharInd = 0; |
101 | |
else |
102 | 0 | ExpandBuff(false); |
103 | |
} |
104 | 0 | else if (available > tokenBegin) |
105 | 0 | available = bufsize; |
106 | 0 | else if ((tokenBegin - available) < 2048) |
107 | 0 | ExpandBuff(true); |
108 | |
else |
109 | 0 | available = tokenBegin; |
110 | |
} |
111 | |
|
112 | |
int i; |
113 | |
try { |
114 | 25 | if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) |
115 | |
{ |
116 | 7 | inputStream.close(); |
117 | 7 | throw new java.io.IOException(); |
118 | |
} |
119 | |
else |
120 | 11 | maxNextCharInd += i; |
121 | 11 | return; |
122 | |
} |
123 | 14 | catch(java.io.IOException e) { |
124 | 14 | --bufpos; |
125 | 14 | backup(0); |
126 | 14 | if (tokenBegin == -1) |
127 | 7 | tokenBegin = bufpos; |
128 | 14 | throw e; |
129 | |
} |
130 | |
} |
131 | |
|
132 | |
|
133 | |
public char BeginToken() throws java.io.IOException |
134 | |
{ |
135 | 59 | tokenBegin = -1; |
136 | 59 | char c = readChar(); |
137 | 52 | tokenBegin = bufpos; |
138 | |
|
139 | 52 | return c; |
140 | |
} |
141 | |
|
142 | |
protected void UpdateLineColumn(char c) |
143 | |
{ |
144 | 1025 | column++; |
145 | |
|
146 | 1025 | if (prevCharIsLF) |
147 | |
{ |
148 | 0 | prevCharIsLF = false; |
149 | 0 | line += (column = 1); |
150 | |
} |
151 | 1025 | else if (prevCharIsCR) |
152 | |
{ |
153 | 0 | prevCharIsCR = false; |
154 | 0 | if (c == '\n') |
155 | |
{ |
156 | 0 | prevCharIsLF = true; |
157 | |
} |
158 | |
else |
159 | 0 | line += (column = 1); |
160 | |
} |
161 | |
|
162 | 1025 | switch (c) |
163 | |
{ |
164 | |
case '\r' : |
165 | 0 | prevCharIsCR = true; |
166 | 0 | break; |
167 | |
case '\n' : |
168 | 0 | prevCharIsLF = true; |
169 | 0 | break; |
170 | |
case '\t' : |
171 | 0 | column--; |
172 | 0 | column += (tabSize - (column % tabSize)); |
173 | 0 | break; |
174 | |
default : |
175 | |
break; |
176 | |
} |
177 | |
|
178 | 1025 | bufline[bufpos] = line; |
179 | 1025 | bufcolumn[bufpos] = column; |
180 | 1025 | } |
181 | |
|
182 | |
|
183 | |
public char readChar() throws java.io.IOException |
184 | |
{ |
185 | 1059 | if (inBuf > 0) |
186 | |
{ |
187 | 20 | --inBuf; |
188 | |
|
189 | 20 | if (++bufpos == bufsize) |
190 | 0 | bufpos = 0; |
191 | |
|
192 | 20 | return buffer[bufpos]; |
193 | |
} |
194 | |
|
195 | 1039 | if (++bufpos >= maxNextCharInd) |
196 | 25 | FillBuff(); |
197 | |
|
198 | 1025 | char c = buffer[bufpos]; |
199 | |
|
200 | 1025 | UpdateLineColumn(c); |
201 | 1025 | return c; |
202 | |
} |
203 | |
|
204 | |
@Deprecated |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public int getColumn() { |
211 | 0 | return bufcolumn[bufpos]; |
212 | |
} |
213 | |
|
214 | |
@Deprecated |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
public int getLine() { |
221 | 0 | return bufline[bufpos]; |
222 | |
} |
223 | |
|
224 | |
|
225 | |
public int getEndColumn() { |
226 | 43 | return bufcolumn[bufpos]; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
public int getEndLine() { |
231 | 43 | return bufline[bufpos]; |
232 | |
} |
233 | |
|
234 | |
|
235 | |
public int getBeginColumn() { |
236 | 43 | return bufcolumn[tokenBegin]; |
237 | |
} |
238 | |
|
239 | |
|
240 | |
public int getBeginLine() { |
241 | 43 | return bufline[tokenBegin]; |
242 | |
} |
243 | |
|
244 | |
|
245 | |
public void backup(int amount) { |
246 | |
|
247 | 70 | inBuf += amount; |
248 | 70 | if ((bufpos -= amount) < 0) |
249 | 0 | bufpos += bufsize; |
250 | 70 | } |
251 | |
|
252 | |
|
253 | |
public SimpleCharStream(java.io.Reader dstream, int startline, |
254 | |
int startcolumn, int buffersize) |
255 | 11 | { |
256 | 11 | inputStream = dstream; |
257 | 11 | line = startline; |
258 | 11 | column = startcolumn - 1; |
259 | |
|
260 | 11 | available = bufsize = buffersize; |
261 | 11 | buffer = new char[buffersize]; |
262 | 11 | bufline = new int[buffersize]; |
263 | 11 | bufcolumn = new int[buffersize]; |
264 | 11 | } |
265 | |
|
266 | |
|
267 | |
public SimpleCharStream(java.io.Reader dstream, int startline, |
268 | |
int startcolumn) |
269 | |
{ |
270 | 11 | this(dstream, startline, startcolumn, 4096); |
271 | 11 | } |
272 | |
|
273 | |
|
274 | |
public SimpleCharStream(java.io.Reader dstream) |
275 | |
{ |
276 | 0 | this(dstream, 1, 1, 4096); |
277 | 0 | } |
278 | |
|
279 | |
|
280 | |
public void ReInit(java.io.Reader dstream, int startline, |
281 | |
int startcolumn, int buffersize) |
282 | |
{ |
283 | 0 | inputStream = dstream; |
284 | 0 | line = startline; |
285 | 0 | column = startcolumn - 1; |
286 | |
|
287 | 0 | if (buffer == null || buffersize != buffer.length) |
288 | |
{ |
289 | 0 | available = bufsize = buffersize; |
290 | 0 | buffer = new char[buffersize]; |
291 | 0 | bufline = new int[buffersize]; |
292 | 0 | bufcolumn = new int[buffersize]; |
293 | |
} |
294 | 0 | prevCharIsLF = prevCharIsCR = false; |
295 | 0 | tokenBegin = inBuf = maxNextCharInd = 0; |
296 | 0 | bufpos = -1; |
297 | 0 | } |
298 | |
|
299 | |
|
300 | |
public void ReInit(java.io.Reader dstream, int startline, |
301 | |
int startcolumn) |
302 | |
{ |
303 | 0 | ReInit(dstream, startline, startcolumn, 4096); |
304 | 0 | } |
305 | |
|
306 | |
|
307 | |
public void ReInit(java.io.Reader dstream) |
308 | |
{ |
309 | 0 | ReInit(dstream, 1, 1, 4096); |
310 | 0 | } |
311 | |
|
312 | |
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, |
313 | |
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException |
314 | |
{ |
315 | 0 | this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); |
316 | 0 | } |
317 | |
|
318 | |
|
319 | |
public SimpleCharStream(java.io.InputStream dstream, int startline, |
320 | |
int startcolumn, int buffersize) |
321 | |
{ |
322 | 0 | this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); |
323 | 0 | } |
324 | |
|
325 | |
|
326 | |
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, |
327 | |
int startcolumn) throws java.io.UnsupportedEncodingException |
328 | |
{ |
329 | 0 | this(dstream, encoding, startline, startcolumn, 4096); |
330 | 0 | } |
331 | |
|
332 | |
|
333 | |
public SimpleCharStream(java.io.InputStream dstream, int startline, |
334 | |
int startcolumn) |
335 | |
{ |
336 | 0 | this(dstream, startline, startcolumn, 4096); |
337 | 0 | } |
338 | |
|
339 | |
|
340 | |
public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException |
341 | |
{ |
342 | 0 | this(dstream, encoding, 1, 1, 4096); |
343 | 0 | } |
344 | |
|
345 | |
|
346 | |
public SimpleCharStream(java.io.InputStream dstream) |
347 | |
{ |
348 | 0 | this(dstream, 1, 1, 4096); |
349 | 0 | } |
350 | |
|
351 | |
|
352 | |
public void ReInit(java.io.InputStream dstream, String encoding, int startline, |
353 | |
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException |
354 | |
{ |
355 | 0 | ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
public void ReInit(java.io.InputStream dstream, int startline, |
360 | |
int startcolumn, int buffersize) |
361 | |
{ |
362 | 0 | ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); |
363 | 0 | } |
364 | |
|
365 | |
|
366 | |
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException |
367 | |
{ |
368 | 0 | ReInit(dstream, encoding, 1, 1, 4096); |
369 | 0 | } |
370 | |
|
371 | |
|
372 | |
public void ReInit(java.io.InputStream dstream) |
373 | |
{ |
374 | 0 | ReInit(dstream, 1, 1, 4096); |
375 | 0 | } |
376 | |
|
377 | |
public void ReInit(java.io.InputStream dstream, String encoding, int startline, |
378 | |
int startcolumn) throws java.io.UnsupportedEncodingException |
379 | |
{ |
380 | 0 | ReInit(dstream, encoding, startline, startcolumn, 4096); |
381 | 0 | } |
382 | |
|
383 | |
public void ReInit(java.io.InputStream dstream, int startline, |
384 | |
int startcolumn) |
385 | |
{ |
386 | 0 | ReInit(dstream, startline, startcolumn, 4096); |
387 | 0 | } |
388 | |
|
389 | |
public String GetImage() |
390 | |
{ |
391 | 24 | if (bufpos >= tokenBegin) |
392 | 24 | return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); |
393 | |
else |
394 | 0 | return new String(buffer, tokenBegin, bufsize - tokenBegin) + |
395 | |
new String(buffer, 0, bufpos + 1); |
396 | |
} |
397 | |
|
398 | |
|
399 | |
public char[] GetSuffix(int len) |
400 | |
{ |
401 | 0 | char[] ret = new char[len]; |
402 | |
|
403 | 0 | if ((bufpos + 1) >= len) |
404 | 0 | System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); |
405 | |
else |
406 | |
{ |
407 | 0 | System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, |
408 | |
len - bufpos - 1); |
409 | 0 | System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); |
410 | |
} |
411 | |
|
412 | 0 | return ret; |
413 | |
} |
414 | |
|
415 | |
|
416 | |
public void Done() |
417 | |
{ |
418 | 0 | buffer = null; |
419 | 0 | bufline = null; |
420 | 0 | bufcolumn = null; |
421 | 0 | } |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
public void adjustBeginLineColumn(int newLine, int newCol) |
427 | |
{ |
428 | 0 | int start = tokenBegin; |
429 | |
int len; |
430 | |
|
431 | 0 | if (bufpos >= tokenBegin) |
432 | |
{ |
433 | 0 | len = bufpos - tokenBegin + inBuf + 1; |
434 | |
} |
435 | |
else |
436 | |
{ |
437 | 0 | len = bufsize - tokenBegin + bufpos + 1 + inBuf; |
438 | |
} |
439 | |
|
440 | 0 | int i = 0, j = 0, k = 0; |
441 | 0 | int nextColDiff = 0, columnDiff = 0; |
442 | |
|
443 | 0 | while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) |
444 | |
{ |
445 | 0 | bufline[j] = newLine; |
446 | 0 | nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; |
447 | 0 | bufcolumn[j] = newCol + columnDiff; |
448 | 0 | columnDiff = nextColDiff; |
449 | 0 | i++; |
450 | |
} |
451 | |
|
452 | 0 | if (i < len) |
453 | |
{ |
454 | 0 | bufline[j] = newLine++; |
455 | 0 | bufcolumn[j] = newCol + columnDiff; |
456 | |
|
457 | 0 | while (i++ < len) |
458 | |
{ |
459 | 0 | if (bufline[j = start % bufsize] != bufline[++start % bufsize]) |
460 | 0 | bufline[j] = newLine++; |
461 | |
else |
462 | 0 | bufline[j] = newLine; |
463 | |
} |
464 | |
} |
465 | |
|
466 | 0 | line = bufline[j]; |
467 | 0 | column = bufcolumn[j]; |
468 | 0 | } |
469 | |
|
470 | |
} |
471 | |
|