1 30 31 32 package org.hsqldb.lib; 33 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 37 43 public class StringInputStream extends InputStream { 44 45 protected int strOffset = 0; 46 protected int charOffset = 0; 47 protected int available; 48 protected String str; 49 50 public StringInputStream(String s) { 51 str = s; 52 available = s.length() * 2; 53 } 54 55 public int read() throws java.io.IOException { 56 57 if (available == 0) { 58 return -1; 59 } 60 61 available--; 62 63 char c = str.charAt(strOffset); 64 65 if (charOffset == 0) { 66 charOffset = 1; 67 68 return (c & 0x0000ff00) >> 8; 69 } else { 70 charOffset = 0; 71 72 strOffset++; 73 74 return c & 0x000000ff; 75 } 76 } 77 78 public int available() throws IOException { 79 return available; 80 } 81 } 82 | Popular Tags |