01: package gnu.mapping;
02:
03: import gnu.text.*;
04: import gnu.lists.Consumer;
05:
06: /** An Inport for reading from a char array.
07: * Essentially the same as an InPort wrapped around a CharArrayReader, but
08: * more efficient because it uses the char array as the InPort's buffer. */
09:
10: public class CharArrayInPort extends InPort {
11: static final Path stringPath = Path.valueOf("<string>");
12:
13: public CharArrayInPort(char[] buffer, int len) {
14: super (NullReader.nullReader, stringPath);
15: try {
16: setBuffer(buffer);
17: } catch (java.io.IOException ex) {
18: throw new Error(ex.toString()); // Can't happen.
19: }
20: limit = len;
21: }
22:
23: public CharArrayInPort(char[] buffer) {
24: this (buffer, buffer.length);
25: }
26:
27: public CharArrayInPort(String string) {
28: this (string.toCharArray());
29: }
30:
31: public int read() throws java.io.IOException {
32: if (pos >= limit)
33: return -1;
34: return super.read();
35: }
36: }
|