1 3 package jodd.io; 4 5 import java.io.IOException ; 6 7 11 public class StringInputStream { 12 13 protected int strOffset = 0; 14 protected int charOffset = 0; 15 protected int available; 16 protected String str; 17 18 public StringInputStream(String s) { 19 str = s; 20 available = s.length() << 1; 21 } 22 23 public int read() throws IOException { 24 if (available == 0) { 25 return -1; 26 } 27 available--; 28 char c = str.charAt(strOffset); 29 if (charOffset == 0) { 30 charOffset = 1; 31 return (c & 0x0000ff00) >> 8; 32 } else { 33 charOffset = 0; 34 strOffset++; 35 return c & 0x000000ff; 36 } 37 } 38 39 public int available() throws IOException { 40 return available; 41 } 42 43 } 44 | Popular Tags |