KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > io > AsciiStringInputStream


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.io;
4
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.io.Serializable JavaDoc;
8
9 /**
10  * Simple InputStream subclass to fetch low order bytes from a String.
11  * @see StringInputStream
12  */

13 public class AsciiStringInputStream extends InputStream JavaDoc implements Serializable JavaDoc {
14
15     protected int strOffset = 0;
16     protected int available;
17     protected String JavaDoc str;
18
19     public AsciiStringInputStream(String JavaDoc s) {
20         str = s;
21         available = s.length();
22     }
23     
24     public int read() throws IOException JavaDoc {
25         if (available == 0) {
26             return -1;
27         }
28         available--;
29         char c = str.charAt(strOffset);
30         strOffset++;
31         return c;
32     }
33
34     public int available() throws IOException JavaDoc {
35         return available;
36     }
37 }
38
Popular Tags