Source Code Cross Referenced for FastCharStream.java in  » Net » lucene-connector » org » apache » lucene » queryParser » precedence » 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 » Net » lucene connector » org.apache.lucene.queryParser.precedence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // FastCharStream.java
002:        package org.apache.lucene.queryParser.precedence;
003:
004:        /**
005:         * Licensed to the Apache Software Foundation (ASF) under one or more
006:         * contributor license agreements.  See the NOTICE file distributed with
007:         * this work for additional information regarding copyright ownership.
008:         * The ASF licenses this file to You under the Apache License, Version 2.0
009:         * (the "License"); you may not use this file except in compliance with
010:         * the License.  You may obtain a copy of the License at
011:         *
012:         *     http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing, software
015:         * distributed under the License is distributed on an "AS IS" BASIS,
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017:         * See the License for the specific language governing permissions and
018:         * limitations under the License.
019:         */
020:
021:        import org.apache.lucene.queryParser.*;
022:
023:        import java.io.*;
024:
025:        /** An efficient implementation of JavaCC's CharStream interface.  <p>Note that
026:         * this does not do line-number counting, but instead keeps track of the
027:         * character position of the token in the input, as required by Lucene's {@link
028:         * org.apache.lucene.analysis.Token} API. */
029:        public final class FastCharStream implements  CharStream {
030:            char[] buffer = null;
031:
032:            int bufferLength = 0; // end of valid chars
033:            int bufferPosition = 0; // next char to read
034:
035:            int tokenStart = 0; // offset in buffer
036:            int bufferStart = 0; // position in file of buffer
037:
038:            Reader input; // source of chars
039:
040:            /** Constructs from a Reader. */
041:            public FastCharStream(Reader r) {
042:                input = r;
043:            }
044:
045:            public final char readChar() throws IOException {
046:                if (bufferPosition >= bufferLength)
047:                    refill();
048:                return buffer[bufferPosition++];
049:            }
050:
051:            private final void refill() throws IOException {
052:                int newPosition = bufferLength - tokenStart;
053:
054:                if (tokenStart == 0) { // token won't fit in buffer
055:                    if (buffer == null) { // first time: alloc buffer
056:                        buffer = new char[2048];
057:                    } else if (bufferLength == buffer.length) { // grow buffer
058:                        char[] newBuffer = new char[buffer.length * 2];
059:                        System.arraycopy(buffer, 0, newBuffer, 0, bufferLength);
060:                        buffer = newBuffer;
061:                    }
062:                } else { // shift token to front
063:                    System
064:                            .arraycopy(buffer, tokenStart, buffer, 0,
065:                                    newPosition);
066:                }
067:
068:                bufferLength = newPosition; // update state
069:                bufferPosition = newPosition;
070:                bufferStart += tokenStart;
071:                tokenStart = 0;
072:
073:                int charsRead = // fill space in buffer
074:                input.read(buffer, newPosition, buffer.length - newPosition);
075:                if (charsRead == -1)
076:                    throw new IOException("read past eof");
077:                else
078:                    bufferLength += charsRead;
079:            }
080:
081:            public final char BeginToken() throws IOException {
082:                tokenStart = bufferPosition;
083:                return readChar();
084:            }
085:
086:            public final void backup(int amount) {
087:                bufferPosition -= amount;
088:            }
089:
090:            public final String GetImage() {
091:                return new String(buffer, tokenStart, bufferPosition
092:                        - tokenStart);
093:            }
094:
095:            public final char[] GetSuffix(int len) {
096:                char[] value = new char[len];
097:                System.arraycopy(buffer, bufferPosition - len, value, 0, len);
098:                return value;
099:            }
100:
101:            public final void Done() {
102:                try {
103:                    input.close();
104:                } catch (IOException e) {
105:                    System.err.println("Caught: " + e + "; ignoring.");
106:                }
107:            }
108:
109:            public final int getColumn() {
110:                return bufferStart + bufferPosition;
111:            }
112:
113:            public final int getLine() {
114:                return 1;
115:            }
116:
117:            public final int getEndColumn() {
118:                return bufferStart + bufferPosition;
119:            }
120:
121:            public final int getEndLine() {
122:                return 1;
123:            }
124:
125:            public final int getBeginColumn() {
126:                return bufferStart + tokenStart;
127:            }
128:
129:            public final int getBeginLine() {
130:                return 1;
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.