KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > mapping > CharArrayInPort


1 package gnu.mapping;
2 import gnu.text.NullReader;
3
4 /** An Inport for reading from a char array.
5   * Essentially the same as an InPort wrapped around a CharArrayReader, but
6   * more efficient because it uses the char array as the InPort's buffer. */

7
8 public class CharArrayInPort extends InPort
9 {
10   public CharArrayInPort (char[] buffer, int len)
11   {
12     super(NullReader.nullReader, "<string>");
13     try
14       {
15     setBuffer(buffer);
16       }
17     catch (java.io.IOException JavaDoc ex)
18       {
19     throw new Error JavaDoc(ex.toString()); // Can't happen.
20
}
21     limit = len;
22   }
23
24   public CharArrayInPort (char[] buffer)
25   {
26     this(buffer, buffer.length);
27   }
28
29   public CharArrayInPort (String JavaDoc string)
30   {
31     this(string.toCharArray());
32   }
33
34   public int read () throws java.io.IOException JavaDoc
35   {
36     if (pos >= limit)
37       return -1;
38     return super.read();
39   }
40 }
41
Popular Tags