KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > persistence > antlr > ByteBuffer


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 // SAS: added this class to handle Binary input w/ FileInputStream
22

23 import java.io.InputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 public class ByteBuffer extends InputBuffer {
27
28     // char source
29
transient InputStream JavaDoc input;
30
31
32     /** Create a character buffer */
33     public ByteBuffer(InputStream JavaDoc input_) {
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