01: package gnu.mapping;
02:
03: import gnu.text.NullReader;
04: import java.io.*;
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: public CharArrayInPort(char[] buffer, int len) {
12: super (NullReader.nullReader, "<string>");
13: try {
14: setBuffer(buffer);
15: } catch (java.io.IOException ex) {
16: throw new Error(ex.toString()); // Can't happen.
17: }
18: limit = len;
19: }
20:
21: public CharArrayInPort(char[] buffer) {
22: this (buffer, buffer.length);
23: }
24:
25: public CharArrayInPort(String string) {
26: this (string.toCharArray());
27: }
28:
29: public int read() throws java.io.IOException {
30: if (pos >= limit)
31: return -1;
32: return super.read();
33: }
34: }
|