01: /*
02: * Created on Nov 11, 2005
03: */
04: package uk.org.ponder.streamutil.read;
05:
06: public class StringRIS implements ReadInputStream {
07: private String read;
08: public int pos = 0;
09:
10: public StringRIS(String target) {
11: this .read = target;
12: }
13:
14: /** Reads a single character from the stream and returns it. If the stream
15: * has reached the end of file, return the value (char)-1.
16: * @return The character that was read.
17: */
18: public char get() {
19: if (pos == read.length()) {
20: return EOF;
21: } else {
22: return read.charAt(pos++);
23: }
24: }
25:
26: public int read(char[] target, int start, int length) {
27: int remain = read.length() - pos;
28: if (length > remain)
29: length = remain;
30: read.getChars(pos, pos + length, target, start);
31: pos += length;
32: return length;
33: }
34:
35: public boolean EOF() {
36: return pos == read.length();
37: }
38:
39: public void close() {
40: }
41: }
|