01: package persistence.antlr;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: /**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: import java.io.InputStream;
23: import java.io.IOException;
24:
25: public class ByteBuffer extends InputBuffer {
26:
27: // char source
28: transient InputStream input;
29:
30: /** Create a character buffer */
31: public ByteBuffer(InputStream input_) {
32: super ();
33: input = input_;
34: }
35:
36: /** Ensure that the character buffer is sufficiently full */
37: public void fill(int amount) throws CharStreamException {
38: try {
39: syncConsume();
40: // Fill the buffer sufficiently to hold needed characters
41: while (queue.nbrEntries < amount + markerOffset) {
42: // Append the next character
43: queue.append((char) input.read());
44: }
45: } catch (IOException io) {
46: throw new CharStreamIOException(io);
47: }
48: }
49: }
|