Source Code Cross Referenced for UCode_UCodeESC_CharStream.java in  » 6.0-JDK-Modules » jaxb-xjc » org » kohsuke » rngom » parse » compact » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jaxb xjc » org.kohsuke.rngom.parse.compact 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Generated By:JavaCC: Do not edit this line. UCode_UCodeESC_CharStream.java Version 0.7pre6 */
002:        /* The previous line keeps JavaCC quiet. In fact, the JavaCC generated file
003:         has been edited to fix some bugs. */
004:        package org.kohsuke.rngom.parse.compact;
005:
006:        import org.kohsuke.rngom.util.Utf16;
007:        import org.kohsuke.rngom.ast.builder.BuildException;
008:
009:        import java.io.IOException;
010:
011:        /**
012:         * An implementation of interface CharStream, where the stream is assumed to
013:         * contain 16-bit unicode characters.
014:         */
015:        public final class UCode_UCodeESC_CharStream {
016:            public static final boolean staticFlag = false;
017:
018:            static final int hexval(char c) {
019:                switch (c) {
020:                case '0':
021:                    return 0;
022:                case '1':
023:                    return 1;
024:                case '2':
025:                    return 2;
026:                case '3':
027:                    return 3;
028:                case '4':
029:                    return 4;
030:                case '5':
031:                    return 5;
032:                case '6':
033:                    return 6;
034:                case '7':
035:                    return 7;
036:                case '8':
037:                    return 8;
038:                case '9':
039:                    return 9;
040:
041:                case 'a':
042:                case 'A':
043:                    return 10;
044:                case 'b':
045:                case 'B':
046:                    return 11;
047:                case 'c':
048:                case 'C':
049:                    return 12;
050:                case 'd':
051:                case 'D':
052:                    return 13;
053:                case 'e':
054:                case 'E':
055:                    return 14;
056:                case 'f':
057:                case 'F':
058:                    return 15;
059:                }
060:                return -1;
061:            }
062:
063:            public int bufpos = -1;
064:            int bufsize;
065:            int available;
066:            int tokenBegin;
067:            private int bufline[];
068:            private int bufcolumn[];
069:
070:            private int column = 0;
071:            private int line = 1;
072:
073:            private java.io.Reader inputStream;
074:            private boolean closed = false;
075:
076:            private boolean prevCharIsLF = false;
077:
078:            private char[] nextCharBuf;
079:            private char[] buffer;
080:            private int maxNextCharInd = 0;
081:            private int nextCharInd = -1;
082:            private int inBuf = 0;
083:
084:            private final void ExpandBuff(boolean wrapAround) {
085:                char[] newbuffer = new char[bufsize + 2048];
086:                int newbufline[] = new int[bufsize + 2048];
087:                int newbufcolumn[] = new int[bufsize + 2048];
088:
089:                if (wrapAround) {
090:                    System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize
091:                            - tokenBegin);
092:                    System.arraycopy(buffer, 0, newbuffer,
093:                            bufsize - tokenBegin, bufpos);
094:                    buffer = newbuffer;
095:
096:                    System.arraycopy(bufline, tokenBegin, newbufline, 0,
097:                            bufsize - tokenBegin);
098:                    System.arraycopy(bufline, 0, newbufline, bufsize
099:                            - tokenBegin, bufpos);
100:                    bufline = newbufline;
101:
102:                    System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0,
103:                            bufsize - tokenBegin);
104:                    System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize
105:                            - tokenBegin, bufpos);
106:                    bufcolumn = newbufcolumn;
107:
108:                    bufpos += (bufsize - tokenBegin);
109:                } else {
110:                    System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize
111:                            - tokenBegin);
112:                    buffer = newbuffer;
113:
114:                    System.arraycopy(bufline, tokenBegin, newbufline, 0,
115:                            bufsize - tokenBegin);
116:                    bufline = newbufline;
117:
118:                    System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0,
119:                            bufsize - tokenBegin);
120:                    bufcolumn = newbufcolumn;
121:
122:                    bufpos -= tokenBegin;
123:                }
124:
125:                available = (bufsize += 2048);
126:                tokenBegin = 0;
127:            }
128:
129:            private final void FillBuff() throws EOFException {
130:                int i;
131:                if (maxNextCharInd == 4096)
132:                    maxNextCharInd = nextCharInd = 0;
133:
134:                if (closed)
135:                    throw new EOFException();
136:                try {
137:                    if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
138:                            4096 - maxNextCharInd)) == -1) {
139:                        closed = true;
140:                        inputStream.close();
141:                        throw new EOFException();
142:                    } else
143:                        maxNextCharInd += i;
144:                } catch (IOException e) {
145:                    throw new BuildException(e);
146:                }
147:            }
148:
149:            private final char ReadChar() throws EOFException {
150:                if (++nextCharInd >= maxNextCharInd)
151:                    FillBuff();
152:
153:                return nextCharBuf[nextCharInd];
154:            }
155:
156:            private final char PeekChar() throws EOFException {
157:                char c = ReadChar();
158:                --nextCharInd;
159:                return c;
160:            }
161:
162:            public final char BeginToken() throws EOFException {
163:                if (inBuf > 0) {
164:                    --inBuf;
165:                    return buffer[tokenBegin = (bufpos == bufsize - 1) ? (bufpos = 0)
166:                            : ++bufpos];
167:                }
168:
169:                tokenBegin = 0;
170:                bufpos = -1;
171:
172:                return readChar();
173:            }
174:
175:            private final void AdjustBuffSize() {
176:                if (available == bufsize) {
177:                    if (tokenBegin > 2048) {
178:                        bufpos = 0;
179:                        available = tokenBegin;
180:                    } else
181:                        ExpandBuff(false);
182:                } else if (available > tokenBegin)
183:                    available = bufsize;
184:                else if ((tokenBegin - available) < 2048)
185:                    ExpandBuff(true);
186:                else
187:                    available = tokenBegin;
188:            }
189:
190:            private final void UpdateLineColumn(char c) {
191:                column++;
192:
193:                if (prevCharIsLF) {
194:                    prevCharIsLF = false;
195:                    line += (column = 1);
196:                }
197:
198:                switch (c) {
199:                case NEWLINE_MARKER:
200:                    prevCharIsLF = true;
201:                    break;
202:                case '\t':
203:                    column--;
204:                    column += (8 - (column & 07));
205:                    break;
206:                default:
207:                    break;
208:                }
209:
210:                bufline[bufpos] = line;
211:                bufcolumn[bufpos] = column;
212:            }
213:
214:            private final char NEWLINE_MARKER = '\u0000';
215:
216:            public final char readChar() throws EOFException {
217:                if (inBuf > 0) {
218:                    --inBuf;
219:                    return buffer[(bufpos == bufsize - 1) ? (bufpos = 0)
220:                            : ++bufpos];
221:                }
222:
223:                char c;
224:                try {
225:                    c = ReadChar();
226:                    switch (c) {
227:                    case '\r':
228:                        c = NEWLINE_MARKER;
229:                        try {
230:                            if (PeekChar() == '\n')
231:                                ReadChar();
232:                        } catch (EOFException e) {
233:                        }
234:                        break;
235:                    case '\n':
236:                        c = NEWLINE_MARKER;
237:                        break;
238:                    case '\t':
239:                        break;
240:                    default:
241:                        if (c >= 0x20) {
242:                            if (Utf16.isSurrogate(c)) {
243:                                if (Utf16.isSurrogate2(c))
244:                                    throw new EscapeSyntaxException(
245:                                            "illegal_surrogate_pair", line,
246:                                            column + 1);
247:                                if (++bufpos == available)
248:                                    AdjustBuffSize();
249:                                buffer[bufpos] = c;
250:                                // UpdateLineColumn(c);
251:                                try {
252:                                    c = ReadChar();
253:                                } catch (EOFException e) {
254:                                    throw new EscapeSyntaxException(
255:                                            "illegal_surrogate_pair", line,
256:                                            column + 1);
257:                                }
258:                                if (!Utf16.isSurrogate2(c))
259:                                    throw new EscapeSyntaxException(
260:                                            "illegal_surrogate_pair", line,
261:                                            column + 2);
262:                            }
263:                            break;
264:                        }
265:                        // fall through
266:                    case '\uFFFE':
267:                    case '\uFFFF':
268:                        throw new EscapeSyntaxException("illegal_char_code",
269:                                line, column + 1);
270:                    }
271:                } catch (EOFException e) {
272:                    if (bufpos == -1) {
273:                        if (++bufpos == available)
274:                            AdjustBuffSize();
275:                        bufline[bufpos] = line;
276:                        bufcolumn[bufpos] = column;
277:                    }
278:                    throw e;
279:                }
280:                if (++bufpos == available)
281:                    AdjustBuffSize();
282:                buffer[bufpos] = c;
283:                UpdateLineColumn(c);
284:                try {
285:                    if (c != '\\' || PeekChar() != 'x')
286:                        return c;
287:                } catch (EOFException e) {
288:                    return c;
289:                }
290:
291:                int xCnt = 1;
292:                for (;;) {
293:                    ReadChar();
294:                    if (++bufpos == available)
295:                        AdjustBuffSize();
296:                    buffer[bufpos] = 'x';
297:                    UpdateLineColumn('x');
298:                    try {
299:                        c = PeekChar();
300:                    } catch (EOFException e) {
301:                        backup(xCnt);
302:                        return '\\';
303:                    }
304:                    if (c == '{') {
305:                        ReadChar();
306:                        column++;
307:                        // backup past the 'x's
308:                        bufpos -= xCnt;
309:                        if (bufpos < 0)
310:                            bufpos += bufsize;
311:                        break;
312:                    }
313:                    if (c != 'x') {
314:                        backup(xCnt);
315:                        return '\\';
316:                    }
317:                    xCnt++;
318:                }
319:                try {
320:                    int scalarValue = hexval(ReadChar());
321:                    column++;
322:                    if (scalarValue < 0)
323:                        throw new EscapeSyntaxException("illegal_hex_digit",
324:                                line, column);
325:                    while ((c = ReadChar()) != '}') {
326:                        column++;
327:                        int n = hexval(c);
328:                        if (n < 0)
329:                            throw new EscapeSyntaxException(
330:                                    "illegal_hex_digit", line, column);
331:                        scalarValue <<= 4;
332:                        scalarValue |= n;
333:                        if (scalarValue >= 0x110000)
334:                            throw new EscapeSyntaxException(
335:                                    "char_code_too_big", line, column);
336:                    }
337:                    column++; // for the '}'
338:                    if (scalarValue <= 0xFFFF) {
339:                        c = (char) scalarValue;
340:                        switch (c) {
341:                        case '\n':
342:                        case '\r':
343:                        case '\t':
344:                            break;
345:                        default:
346:                            if (c >= 0x20 && !Utf16.isSurrogate(c))
347:                                break;
348:                            // fall through
349:                        case '\uFFFE':
350:                        case '\uFFFF':
351:                            throw new EscapeSyntaxException(
352:                                    "illegal_char_code_ref", line, column);
353:                        }
354:                        buffer[bufpos] = c;
355:                        return c;
356:                    }
357:                    c = Utf16.surrogate1(scalarValue);
358:                    buffer[bufpos] = c;
359:                    int bufpos1 = bufpos;
360:                    if (++bufpos == bufsize)
361:                        bufpos = 0;
362:                    buffer[bufpos] = Utf16.surrogate2(scalarValue);
363:                    bufline[bufpos] = bufline[bufpos1];
364:                    bufcolumn[bufpos] = bufcolumn[bufpos1];
365:                    backup(1);
366:                    return c;
367:                } catch (EOFException e) {
368:                    throw new EscapeSyntaxException("incomplete_escape", line,
369:                            column);
370:                }
371:            }
372:
373:            /**
374:             * @deprecated
375:             * @see #getEndColumn
376:             */
377:
378:            public final int getColumn() {
379:                return bufcolumn[bufpos];
380:            }
381:
382:            /**
383:             * @deprecated
384:             * @see #getEndLine
385:             */
386:
387:            public final int getLine() {
388:                return bufline[bufpos];
389:            }
390:
391:            public final int getEndColumn() {
392:                return bufcolumn[bufpos];
393:            }
394:
395:            public final int getEndLine() {
396:                return bufline[bufpos];
397:            }
398:
399:            public final int getBeginColumn() {
400:                return bufcolumn[tokenBegin];
401:            }
402:
403:            public final int getBeginLine() {
404:                return bufline[tokenBegin];
405:            }
406:
407:            public final void backup(int amount) {
408:
409:                inBuf += amount;
410:                if ((bufpos -= amount) < 0)
411:                    bufpos += bufsize;
412:            }
413:
414:            public UCode_UCodeESC_CharStream(java.io.Reader dstream,
415:                    int startline, int startcolumn, int buffersize) {
416:                inputStream = dstream;
417:                line = startline;
418:                column = startcolumn - 1;
419:
420:                available = bufsize = buffersize;
421:                buffer = new char[buffersize];
422:                bufline = new int[buffersize];
423:                bufcolumn = new int[buffersize];
424:                nextCharBuf = new char[4096];
425:                skipBOM();
426:            }
427:
428:            public UCode_UCodeESC_CharStream(java.io.Reader dstream,
429:                    int startline, int startcolumn) {
430:                this (dstream, startline, startcolumn, 4096);
431:            }
432:
433:            public void ReInit(java.io.Reader dstream, int startline,
434:                    int startcolumn, int buffersize) {
435:                inputStream = dstream;
436:                closed = false;
437:                line = startline;
438:                column = startcolumn - 1;
439:
440:                if (buffer == null || buffersize != buffer.length) {
441:                    available = bufsize = buffersize;
442:                    buffer = new char[buffersize];
443:                    bufline = new int[buffersize];
444:                    bufcolumn = new int[buffersize];
445:                    nextCharBuf = new char[4096];
446:                }
447:                prevCharIsLF = false;
448:                tokenBegin = inBuf = maxNextCharInd = 0;
449:                nextCharInd = bufpos = -1;
450:                skipBOM();
451:            }
452:
453:            public void ReInit(java.io.Reader dstream, int startline,
454:                    int startcolumn) {
455:                ReInit(dstream, startline, startcolumn, 4096);
456:            }
457:
458:            public UCode_UCodeESC_CharStream(java.io.InputStream dstream,
459:                    int startline, int startcolumn, int buffersize) {
460:                this (new java.io.InputStreamReader(dstream), startline,
461:                        startcolumn, 4096);
462:            }
463:
464:            public UCode_UCodeESC_CharStream(java.io.InputStream dstream,
465:                    int startline, int startcolumn) {
466:                this (dstream, startline, startcolumn, 4096);
467:            }
468:
469:            public void ReInit(java.io.InputStream dstream, int startline,
470:                    int startcolumn, int buffersize) {
471:                ReInit(new java.io.InputStreamReader(dstream), startline,
472:                        startcolumn, 4096);
473:            }
474:
475:            public void ReInit(java.io.InputStream dstream, int startline,
476:                    int startcolumn) {
477:                ReInit(dstream, startline, startcolumn, 4096);
478:            }
479:
480:            static private final char BOM = '\ufeff';
481:
482:            private void skipBOM() {
483:                try {
484:                    if (PeekChar() == BOM)
485:                        ReadChar();
486:                } catch (EOFException e) {
487:                }
488:            }
489:
490:            public final String GetImage() {
491:                if (bufpos >= tokenBegin)
492:                    return new String(buffer, tokenBegin, bufpos - tokenBegin
493:                            + 1);
494:                else
495:                    return new String(buffer, tokenBegin, bufsize - tokenBegin)
496:                            + new String(buffer, 0, bufpos + 1);
497:            }
498:
499:            public final char[] GetSuffix(int len) {
500:                char[] ret = new char[len];
501:
502:                if ((bufpos + 1) >= len)
503:                    System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
504:                else {
505:                    System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret,
506:                            0, len - bufpos - 1);
507:                    System.arraycopy(buffer, 0, ret, len - bufpos - 1,
508:                            bufpos + 1);
509:                }
510:
511:                return ret;
512:            }
513:
514:            public void Done() {
515:                nextCharBuf = null;
516:                buffer = null;
517:                bufline = null;
518:                bufcolumn = null;
519:            }
520:
521:            /**
522:             * Method to adjust line and column numbers for the start of a token.<BR>
523:             */
524:            public void adjustBeginLineColumn(int newLine, int newCol) {
525:                int start = tokenBegin;
526:                int len;
527:
528:                if (bufpos >= tokenBegin) {
529:                    len = bufpos - tokenBegin + inBuf + 1;
530:                } else {
531:                    len = bufsize - tokenBegin + bufpos + 1 + inBuf;
532:                }
533:
534:                int i = 0, j = 0, k = 0;
535:                int nextColDiff = 0, columnDiff = 0;
536:
537:                while (i < len
538:                        && bufline[j = start % bufsize] == bufline[k = ++start
539:                                % bufsize]) {
540:                    bufline[j] = newLine;
541:                    nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
542:                    bufcolumn[j] = newCol + columnDiff;
543:                    columnDiff = nextColDiff;
544:                    i++;
545:                }
546:
547:                if (i < len) {
548:                    bufline[j] = newLine++;
549:                    bufcolumn[j] = newCol + columnDiff;
550:
551:                    while (i++ < len) {
552:                        if (bufline[j = start % bufsize] != bufline[++start
553:                                % bufsize])
554:                            bufline[j] = newLine++;
555:                        else
556:                            bufline[j] = newLine;
557:                    }
558:                }
559:
560:                line = bufline[j];
561:                column = bufcolumn[j];
562:            }
563:
564:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.