KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > CharBuffer


1 package persistence.antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/license.html
6  *
7  */

8
9 /**A Stream of characters fed to the lexer from a InputStream that can
10  * be rewound via mark()/rewind() methods.
11  * <p>
12  * A dynamic array is used to buffer up all the input characters. Normally,
13  * "k" characters are stored in the buffer. More characters may be stored during
14  * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
15  * Consumption of characters is deferred. In other words, reading the next
16  * character is not done by conume(), but deferred until needed by LA or LT.
17  * <p>
18  *
19  * @see persistence.antlr.CharQueue
20  */

21
22 import java.io.Reader JavaDoc; // SAS: changed to properly read text files
23
import java.io.IOException JavaDoc;
24
25 // SAS: Move most functionality into InputBuffer -- just the file-specific
26
// stuff is in here
27

28 public class CharBuffer extends InputBuffer {
29     // char source
30
transient Reader JavaDoc input;
31
32     /** Create a character buffer */
33     public CharBuffer(Reader JavaDoc input_) { // SAS: for proper text i/o
34
super();
35         input = input_;
36     }
37
38     /** Ensure that the character buffer is sufficiently full */
39     public void fill(int amount) throws CharStreamException {
40         try {
41             syncConsume();
42             // Fill the buffer sufficiently to hold needed characters
43
while (queue.nbrEntries < amount + markerOffset) {
44                 // Append the next character
45
queue.append((char)input.read());
46             }
47         }
48         catch (IOException JavaDoc io) {
49             throw new CharStreamIOException(io);
50         }
51     }
52 }
53
Popular Tags