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.InputStream; |
58 |
| |
59 |
| import org.w3c.tidy.EncodingUtils.GetBytes; |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| public class StreamInImpl implements StreamIn |
71 |
| { |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| private static final int CHARBUF_SIZE = 5; |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| private Lexer lexer; |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| private int[] charbuf = new int[CHARBUF_SIZE]; |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| private int bufpos; |
92 |
| |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| |
98 |
| private char[] rawBytebuf = new char[CHARBUF_SIZE]; |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| private int rawBufpos; |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
| private boolean rawPushed; |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| private boolean lookingForBOM = true; |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| private boolean endOfStream; |
119 |
| |
120 |
| private boolean pushed; |
121 |
| |
122 |
| private int tabs; |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| private int tabsize; |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| private int state; |
133 |
| |
134 |
| |
135 |
| |
136 |
| |
137 |
| private int encoding; |
138 |
| |
139 |
| |
140 |
| |
141 |
| |
142 |
| private int curcol; |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
| private int lastcol; |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| private int curline; |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
| private InputStream stream; |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| private GetBytes getBytes; |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
| private boolean rawOut; |
168 |
| |
169 |
| |
170 |
| |
171 |
| |
172 |
| |
173 |
| |
174 |
8
| public StreamInImpl(InputStream stream, Configuration configuration)
|
175 |
| { |
176 |
8
| this.stream = stream;
|
177 |
8
| this.charbuf[0] = '\0';
|
178 |
8
| this.tabsize = configuration.tabsize;
|
179 |
8
| this.curline = 1;
|
180 |
8
| this.curcol = 1;
|
181 |
8
| this.encoding = configuration.getInCharEncoding();
|
182 |
8
| this.rawOut = configuration.rawOut;
|
183 |
8
| this.state = EncodingUtils.FSM_ASCII;
|
184 |
8
| this.getBytes = new GetBytes()
|
185 |
| { |
186 |
| |
187 |
| StreamInImpl in; |
188 |
| |
189 |
8
| GetBytes setStreamIn(StreamInImpl in)
|
190 |
| { |
191 |
8
| this.in = in;
|
192 |
8
| return this;
|
193 |
| } |
194 |
| |
195 |
0
| public void doGet(int[] buf, int[] count, boolean unget)
|
196 |
| { |
197 |
0
| in.readRawBytesFromStream(buf, count, unget);
|
198 |
| } |
199 |
| } |
200 |
| .setStreamIn(this); |
201 |
| } |
202 |
| |
203 |
| |
204 |
| |
205 |
| |
206 |
0
| public int getCurcol()
|
207 |
| { |
208 |
0
| return this.curcol;
|
209 |
| } |
210 |
| |
211 |
| |
212 |
| |
213 |
| |
214 |
0
| public int getCurline()
|
215 |
| { |
216 |
0
| return this.curline;
|
217 |
| } |
218 |
| |
219 |
| |
220 |
| |
221 |
| |
222 |
| |
223 |
8
| public void setLexer(Lexer lexer)
|
224 |
| { |
225 |
8
| this.lexer = lexer;
|
226 |
| } |
227 |
| |
228 |
| |
229 |
| |
230 |
| |
231 |
0
| public int readChar()
|
232 |
| { |
233 |
0
| int c;
|
234 |
| |
235 |
0
| if (this.pushed)
|
236 |
| { |
237 |
0
| c = this.charbuf[--(this.bufpos)];
|
238 |
0
| if ((this.bufpos) == 0)
|
239 |
| { |
240 |
0
| this.pushed = false;
|
241 |
| } |
242 |
| |
243 |
0
| if (c == '\n')
|
244 |
| { |
245 |
0
| this.curcol = 1;
|
246 |
0
| this.curline++;
|
247 |
| } |
248 |
| else |
249 |
| { |
250 |
0
| this.curcol++;
|
251 |
| } |
252 |
| |
253 |
0
| return c;
|
254 |
| } |
255 |
| |
256 |
0
| this.lastcol = this.curcol;
|
257 |
| |
258 |
0
| if (this.tabs > 0)
|
259 |
| { |
260 |
0
| this.curcol++;
|
261 |
0
| this.tabs--;
|
262 |
0
| return ' ';
|
263 |
| } |
264 |
| |
265 |
0
| while (true)
|
266 |
| { |
267 |
0
| c = readCharFromStream();
|
268 |
| |
269 |
0
| if (c < 0)
|
270 |
| { |
271 |
0
| return END_OF_STREAM;
|
272 |
| } |
273 |
| |
274 |
0
| if (c == '\n')
|
275 |
| { |
276 |
0
| this.curcol = 1;
|
277 |
0
| this.curline++;
|
278 |
0
| break;
|
279 |
| } |
280 |
| |
281 |
| |
282 |
0
| if (c == '\r')
|
283 |
| { |
284 |
0
| c = readCharFromStream();
|
285 |
0
| if (c != '\n')
|
286 |
| { |
287 |
0
| if (c != END_OF_STREAM)
|
288 |
| { |
289 |
0
| ungetChar(c);
|
290 |
| } |
291 |
0
| c = '\n';
|
292 |
| } |
293 |
0
| this.curcol = 1;
|
294 |
0
| this.curline++;
|
295 |
0
| break;
|
296 |
| } |
297 |
| |
298 |
0
| if (c == '\t')
|
299 |
| { |
300 |
0
| this.tabs = this.tabsize - ((this.curcol - 1) % this.tabsize) - 1;
|
301 |
0
| this.curcol++;
|
302 |
0
| c = ' ';
|
303 |
0
| break;
|
304 |
| } |
305 |
| |
306 |
| |
307 |
0
| if (c == '\033')
|
308 |
| { |
309 |
0
| break;
|
310 |
| } |
311 |
0
| else if (c == '\015' && !lexer.configuration.xmlTags)
|
312 |
| { |
313 |
0
| break;
|
314 |
| } |
315 |
0
| else if (0 < c && c < 32)
|
316 |
| { |
317 |
0
| continue;
|
318 |
| } |
319 |
| |
320 |
| |
321 |
| |
322 |
0
| if (rawOut
|
323 |
| || this.encoding == Configuration.ISO2022 |
324 |
| || this.encoding == Configuration.UTF8 |
325 |
| || this.encoding == Configuration.SHIFTJIS |
326 |
| || this.encoding == Configuration.BIG5) |
327 |
| { |
328 |
0
| this.curcol++;
|
329 |
0
| break;
|
330 |
| } |
331 |
| |
332 |
| |
333 |
0
| if ((this.encoding == Configuration.UTF16LE)
|
334 |
| || (this.encoding == Configuration.UTF16) |
335 |
| || (this.encoding == Configuration.UTF16BE)) |
336 |
| { |
337 |
0
| if (c > EncodingUtils.MAX_UTF8_FROM_UCS4)
|
338 |
| { |
339 |
| |
340 |
0
| this.lexer.report.encodingError(this.lexer, Report.INVALID_UTF16 | Report.DISCARDED_CHAR, c);
|
341 |
0
| c = 0;
|
342 |
| } |
343 |
| |
344 |
0
| else if (c >= EncodingUtils.UTF16_LOW_SURROGATE_BEGIN && c <= EncodingUtils.UTF16_LOW_SURROGATE_END)
|
345 |
| { |
346 |
0
| int n, m;
|
347 |
| |
348 |
0
| n = c;
|
349 |
| |
350 |
0
| m = readCharFromStream();
|
351 |
0
| if (m < 0)
|
352 |
| { |
353 |
0
| return END_OF_STREAM;
|
354 |
| } |
355 |
| |
356 |
0
| if (m >= EncodingUtils.UTF16_HIGH_SURROGATE_BEGIN && m <= EncodingUtils.UTF16_HIGH_SURROGATE_END)
|
357 |
| { |
358 |
| |
359 |
0
| c = (n - EncodingUtils.UTF16_LOW_SURROGATE_BEGIN)
|
360 |
| * 0x400 |
361 |
| + (m - EncodingUtils.UTF16_HIGH_SURROGATE_BEGIN) |
362 |
| + 0x10000; |
363 |
| |
364 |
| |
365 |
0
| if (((c & 0x0000FFFE) == 0x0000FFFE)
|
366 |
| || ((c & 0x0000FFFF) == 0x0000FFFF) |
367 |
| || (c < EncodingUtils.UTF16_SURROGATES_BEGIN)) |
368 |
| { |
369 |
0
| this.lexer.report
|
370 |
| .encodingError(this.lexer, Report.INVALID_UTF16 | Report.DISCARDED_CHAR, c); |
371 |
0
| c = 0;
|
372 |
| } |
373 |
| } |
374 |
| else |
375 |
| { |
376 |
| |
377 |
0
| this.lexer.report.encodingError(this.lexer, Report.INVALID_UTF16 | Report.DISCARDED_CHAR, c);
|
378 |
0
| c = 0;
|
379 |
| |
380 |
| } |
381 |
| } |
382 |
| else |
383 |
| { |
384 |
| |
385 |
| } |
386 |
| } |
387 |
| |
388 |
0
| if (this.encoding == Configuration.MACROMAN)
|
389 |
| { |
390 |
0
| c = EncodingUtils.decodeMacRoman(c);
|
391 |
| } |
392 |
| |
393 |
| |
394 |
| |
395 |
0
| if (127 < c && c < 160)
|
396 |
| { |
397 |
0
| int c1 = 0;
|
398 |
0
| int replaceMode;
|
399 |
| |
400 |
| |
401 |
0
| this.lexer.lines = this.curline;
|
402 |
0
| this.lexer.columns = this.curcol;
|
403 |
| |
404 |
0
| if ((this.encoding == Configuration.WIN1252)
|
405 |
| || (this.lexer.configuration.replacementCharEncoding == Configuration.WIN1252)) |
406 |
| { |
407 |
0
| c1 = EncodingUtils.decodeWin1252(c);
|
408 |
| } |
409 |
0
| else if (this.lexer.configuration.replacementCharEncoding == Configuration.MACROMAN)
|
410 |
| { |
411 |
0
| c1 = EncodingUtils.decodeMacRoman(c);
|
412 |
| } |
413 |
| |
414 |
0
| replaceMode = TidyUtils.toBoolean(c1) ? Report.REPLACED_CHAR : Report.DISCARDED_CHAR;
|
415 |
| |
416 |
0
| if ((c1 == 0) && (this.encoding == Configuration.WIN1252) || (this.encoding == Configuration.MACROMAN))
|
417 |
| { |
418 |
0
| this.lexer.report.encodingError(this.lexer, Report.VENDOR_SPECIFIC_CHARS | replaceMode, c);
|
419 |
| } |
420 |
0
| else if ((this.encoding != Configuration.WIN1252) && (this.encoding != Configuration.MACROMAN))
|
421 |
| { |
422 |
0
| this.lexer.report.encodingError(this.lexer, Report.INVALID_SGML_CHARS | replaceMode, c);
|
423 |
| } |
424 |
| |
425 |
0
| c = c1;
|
426 |
| } |
427 |
| |
428 |
0
| if (c == 0)
|
429 |
| { |
430 |
0
| continue;
|
431 |
| } |
432 |
| |
433 |
0
| this.curcol++;
|
434 |
0
| break;
|
435 |
| } |
436 |
| |
437 |
0
| return c;
|
438 |
| } |
439 |
| |
440 |
| |
441 |
| |
442 |
| |
443 |
0
| public void ungetChar(int c)
|
444 |
| { |
445 |
0
| this.pushed = true;
|
446 |
0
| if (this.bufpos >= CHARBUF_SIZE)
|
447 |
| { |
448 |
| |
449 |
0
| System.arraycopy(this.charbuf, 0, this.charbuf, 1, CHARBUF_SIZE - 1);
|
450 |
0
| this.bufpos--;
|
451 |
| } |
452 |
0
| this.charbuf[(this.bufpos)++] = c;
|
453 |
| |
454 |
0
| if (c == '\n')
|
455 |
| { |
456 |
0
| --this.curline;
|
457 |
| } |
458 |
| |
459 |
0
| this.curcol = this.lastcol;
|
460 |
| } |
461 |
| |
462 |
| |
463 |
| |
464 |
| |
465 |
0
| public boolean isEndOfStream()
|
466 |
| { |
467 |
0
| return this.endOfStream;
|
468 |
| } |
469 |
| |
470 |
| |
471 |
| |
472 |
| |
473 |
8
| public int readCharFromStream()
|
474 |
| { |
475 |
8
| int c;
|
476 |
8
| int[] n = new int[]{0};
|
477 |
8
| int[] tempchar = new int[1];
|
478 |
8
| int[] count = new int[]{1};
|
479 |
| |
480 |
8
| readRawBytesFromStream(tempchar, count, false);
|
481 |
8
| if (count[0] <= 0)
|
482 |
| { |
483 |
0
| endOfStream = true;
|
484 |
0
| return END_OF_STREAM;
|
485 |
| } |
486 |
| |
487 |
8
| c = tempchar[0];
|
488 |
| |
489 |
8
| if (lookingForBOM
|
490 |
| && (this.encoding == Configuration.UTF16 |
491 |
| || this.encoding == Configuration.UTF16LE |
492 |
| || this.encoding == Configuration.UTF16BE || this.encoding == Configuration.UTF8)) |
493 |
| { |
494 |
| |
495 |
3
| int c1, bom;
|
496 |
| |
497 |
3
| lookingForBOM = false;
|
498 |
| |
499 |
3
| if (c == END_OF_STREAM)
|
500 |
| { |
501 |
0
| lookingForBOM = false;
|
502 |
0
| endOfStream = true;
|
503 |
0
| return END_OF_STREAM;
|
504 |
| } |
505 |
| |
506 |
3
| count[0] = 1;
|
507 |
3
| readRawBytesFromStream(tempchar, count, false);
|
508 |
3
| c1 = tempchar[0];
|
509 |
| |
510 |
3
| bom = (c << 8) + c1;
|
511 |
| |
512 |
3
| if (bom == EncodingUtils.UNICODE_BOM_BE)
|
513 |
| { |
514 |
| |
515 |
1
| if (this.encoding != Configuration.UTF16 && this.encoding != Configuration.UTF16BE)
|
516 |
| { |
517 |
0
| this.lexer.report.encodingError(this.lexer, Report.ENCODING_MISMATCH, Configuration.UTF16BE);
|
518 |
| |
519 |
| } |
520 |
1
| this.encoding = Configuration.UTF16BE;
|
521 |
1
| this.lexer.configuration.setInCharEncoding(Configuration.UTF16BE);
|
522 |
1
| return EncodingUtils.UNICODE_BOM;
|
523 |
| } |
524 |
2
| else if (bom == EncodingUtils.UNICODE_BOM_LE)
|
525 |
| { |
526 |
| |
527 |
1
| if (this.encoding != Configuration.UTF16 && this.encoding != Configuration.UTF16LE)
|
528 |
| { |
529 |
0
| this.lexer.report.encodingError(this.lexer, Report.ENCODING_MISMATCH, Configuration.UTF16LE);
|
530 |
| |
531 |
| } |
532 |
1
| this.encoding = Configuration.UTF16LE;
|
533 |
1
| this.lexer.configuration.setInCharEncoding(Configuration.UTF16LE);
|
534 |
1
| return EncodingUtils.UNICODE_BOM;
|
535 |
| } |
536 |
| else |
537 |
| { |
538 |
1
| int c2;
|
539 |
| |
540 |
1
| count[0] = 1;
|
541 |
1
| readRawBytesFromStream(tempchar, count, false);
|
542 |
1
| c2 = tempchar[0];
|
543 |
| |
544 |
1
| if (((c << 16) + (c1 << 8) + c2) == EncodingUtils.UNICODE_BOM_UTF8)
|
545 |
| { |
546 |
| |
547 |
0
| this.encoding = Configuration.UTF8;
|
548 |
0
| if (this.encoding != Configuration.UTF8)
|
549 |
| { |
550 |
0
| this.lexer.report.encodingError(this.lexer, Report.ENCODING_MISMATCH, Configuration.UTF8);
|
551 |
| |
552 |
| } |
553 |
0
| this.lexer.configuration.setInCharEncoding(Configuration.UTF8);
|
554 |
0
| return EncodingUtils.UNICODE_BOM;
|
555 |
| } |
556 |
| |
557 |
| |
558 |
1
| rawPushed = true;
|
559 |
| |
560 |
1
| if ((rawBufpos + 1) >= CHARBUF_SIZE)
|
561 |
| { |
562 |
0
| System.arraycopy(rawBytebuf, 2, rawBytebuf, 0, CHARBUF_SIZE - 2);
|
563 |
0
| rawBufpos -= 2;
|
564 |
| } |
565 |
| |
566 |
1
| rawBytebuf[rawBufpos++] = (char) c2;
|
567 |
1
| rawBytebuf[rawBufpos++] = (char) c1;
|
568 |
| |
569 |
| |
570 |
| } |
571 |
| } |
572 |
| |
573 |
6
| this.lookingForBOM = false;
|
574 |
| |
575 |
| |
576 |
| |
577 |
| |
578 |
| |
579 |
| |
580 |
| |
581 |
| |
582 |
6
| if (this.encoding == Configuration.ISO2022)
|
583 |
| { |
584 |
0
| if (c == 0x1b)
|
585 |
| { |
586 |
0
| this.state = EncodingUtils.FSM_ESC;
|
587 |
0
| return c;
|
588 |
| } |
589 |
| |
590 |
0
| switch (this.state)
|
591 |
| { |
592 |
0
| case EncodingUtils.FSM_ESC :
|
593 |
0
| if (c == '$')
|
594 |
| { |
595 |
0
| this.state = EncodingUtils.FSM_ESCD;
|
596 |
| } |
597 |
0
| else if (c == '(')
|
598 |
| { |
599 |
0
| this.state = EncodingUtils.FSM_ESCP;
|
600 |
| } |
601 |
| else |
602 |
| { |
603 |
0
| this.state = EncodingUtils.FSM_ASCII;
|
604 |
| } |
605 |
0
| break;
|
606 |
| |
607 |
0
| case EncodingUtils.FSM_ESCD :
|
608 |
0
| if (c == '(')
|
609 |
| { |
610 |
0
| this.state = EncodingUtils.FSM_ESCDP;
|
611 |
| } |
612 |
| else |
613 |
| { |
614 |
0
| this.state = EncodingUtils.FSM_NONASCII;
|
615 |
| } |
616 |
0
| break;
|
617 |
| |
618 |
0
| case EncodingUtils.FSM_ESCDP :
|
619 |
0
| this.state = EncodingUtils.FSM_NONASCII;
|
620 |
0
| break;
|
621 |
| |
622 |
0
| case EncodingUtils.FSM_ESCP :
|
623 |
0
| this.state = EncodingUtils.FSM_ASCII;
|
624 |
0
| break;
|
625 |
| |
626 |
0
| case EncodingUtils.FSM_NONASCII :
|
627 |
0
| c |= 0x80;
|
628 |
0
| break;
|
629 |
| |
630 |
0
| default :
|
631 |
| |
632 |
0
| break;
|
633 |
| } |
634 |
| |
635 |
0
| return c;
|
636 |
| } |
637 |
| |
638 |
6
| if (this.encoding == Configuration.UTF16LE)
|
639 |
| { |
640 |
1
| int c1;
|
641 |
| |
642 |
1
| count[0] = 1;
|
643 |
1
| readRawBytesFromStream(tempchar, count, false);
|
644 |
1
| if (count[0] <= 0)
|
645 |
| { |
646 |
0
| endOfStream = true;
|
647 |
0
| return END_OF_STREAM;
|
648 |
| } |
649 |
1
| c1 = tempchar[0];
|
650 |
| |
651 |
1
| n[0] = (c1 << 8) + c;
|
652 |
| |
653 |
1
| return n[0];
|
654 |
| } |
655 |
| |
656 |
| |
657 |
5
| if ((this.encoding == Configuration.UTF16) || (this.encoding == Configuration.UTF16BE))
|
658 |
| { |
659 |
3
| int c1;
|
660 |
| |
661 |
3
| count[0] = 1;
|
662 |
3
| readRawBytesFromStream(tempchar, count, false);
|
663 |
3
| if (count[0] <= 0)
|
664 |
| { |
665 |
0
| endOfStream = true;
|
666 |
0
| return END_OF_STREAM;
|
667 |
| } |
668 |
3
| c1 = tempchar[0];
|
669 |
| |
670 |
3
| n[0] = (c << 8) + c1;
|
671 |
| |
672 |
3
| return n[0];
|
673 |
| } |
674 |
| |
675 |
2
| if (this.encoding == Configuration.UTF8)
|
676 |
| { |
677 |
| |
678 |
0
| int[] count2 = new int[]{0};
|
679 |
| |
680 |
| |
681 |
0
| boolean err = EncodingUtils.decodeUTF8BytesToChar(n, c, new byte[0], this.getBytes, count2, 0);
|
682 |
0
| if (!err && (n[0] == END_OF_STREAM) && (count2[0] == 1))
|
683 |
| { |
684 |
0
| endOfStream = true;
|
685 |
0
| return END_OF_STREAM;
|
686 |
| } |
687 |
0
| else if (err)
|
688 |
| { |
689 |
| |
690 |
0
| this.lexer.lines = this.curline;
|
691 |
0
| this.lexer.columns = this.curcol;
|
692 |
| |
693 |
0
| this.lexer.report.encodingError(this.lexer, (short) (Report.INVALID_UTF8 | Report.REPLACED_CHAR), n[0]);
|
694 |
0
| n[0] = 0xFFFD;
|
695 |
| } |
696 |
| |
697 |
0
| return n[0];
|
698 |
| } |
699 |
| |
700 |
| |
701 |
| |
702 |
| |
703 |
| |
704 |
| |
705 |
2
| if ((this.encoding == Configuration.BIG5) || (this.encoding == Configuration.SHIFTJIS))
|
706 |
| { |
707 |
0
| if (c < 128)
|
708 |
| { |
709 |
0
| return c;
|
710 |
| } |
711 |
0
| else if ((this.encoding == Configuration.SHIFTJIS) && (c >= 0xa1 && c <= 0xdf))
|
712 |
| { |
713 |
| |
714 |
| |
715 |
| |
716 |
0
| return c;
|
717 |
| } |
718 |
| else |
719 |
| { |
720 |
0
| int c1;
|
721 |
0
| count[0] = 1;
|
722 |
0
| readRawBytesFromStream(tempchar, count, false);
|
723 |
| |
724 |
0
| if (count[0] <= 0)
|
725 |
| { |
726 |
0
| endOfStream = true;
|
727 |
0
| return END_OF_STREAM;
|
728 |
| } |
729 |
| |
730 |
0
| c1 = tempchar[0];
|
731 |
0
| n[0] = (c << 8) + c1;
|
732 |
0
| return n[0];
|
733 |
| } |
734 |
| } |
735 |
| |
736 |
2
| n[0] = c;
|
737 |
| |
738 |
2
| return n[0];
|
739 |
| } |
740 |
| |
741 |
| |
742 |
| |
743 |
| |
744 |
| |
745 |
| |
746 |
| |
747 |
| |
748 |
16
| protected void readRawBytesFromStream(int[] buf, int[] count, boolean unget)
|
749 |
| { |
750 |
| |
751 |
16
| try
|
752 |
| { |
753 |
16
| for (int i = 0; i < count[0]; i++)
|
754 |
| { |
755 |
16
| if (unget)
|
756 |
| { |
757 |
| |
758 |
0
| int c = this.stream.read();
|
759 |
| |
760 |
| |
761 |
0
| if (c == END_OF_STREAM)
|
762 |
| { |
763 |
0
| count[0] = -i;
|
764 |
0
| return;
|
765 |
| } |
766 |
| |
767 |
0
| rawPushed = true;
|
768 |
| |
769 |
0
| if (rawBufpos >= CHARBUF_SIZE)
|
770 |
| { |
771 |
0
| System.arraycopy(rawBytebuf, 1, rawBytebuf, 0, CHARBUF_SIZE - 1);
|
772 |
0
| rawBufpos--;
|
773 |
| } |
774 |
0
| rawBytebuf[rawBufpos++] = (char) buf[i];
|
775 |
| } |
776 |
| else |
777 |
| { |
778 |
16
| if (rawPushed)
|
779 |
| { |
780 |
2
| buf[i] = rawBytebuf[--rawBufpos];
|
781 |
2
| if (rawBufpos == 0)
|
782 |
| { |
783 |
1
| rawPushed = false;
|
784 |
| } |
785 |
| } |
786 |
| else |
787 |
| { |
788 |
14
| int c = this.stream.read();
|
789 |
14
| if (c == END_OF_STREAM)
|
790 |
| { |
791 |
0
| count[0] = -i;
|
792 |
0
| break;
|
793 |
| } |
794 |
14
| buf[i] = (char) c;
|
795 |
| } |
796 |
| } |
797 |
| } |
798 |
| } |
799 |
| catch (IOException e) |
800 |
| { |
801 |
0
| System.err.println("StreamInImpl.readRawBytesFromStream: " + e.toString());
|
802 |
| } |
803 |
16
| return;
|
804 |
| } |
805 |
| |
806 |
| } |