KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > ByteBuffer


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/ByteBuffer.java#4 $
8  */

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

22 // SAS: added this class to handle Binary input w/ FileInputStream
23

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