1 package com.quadcap.sql.types; 2 3 40 41 import java.io.IOException ; 42 import java.io.InputStream ; 43 import java.io.Reader ; 44 45 import com.quadcap.util.Debug; 46 47 54 public class ByteReader extends Reader { 55 InputStream in; 56 57 public ByteReader(InputStream in) { 58 this.in = in; 59 } 60 61 public int read() throws IOException { 62 int c = in.read(); 63 if (c < 0) return -1; 64 int c2 = in.read(); 65 if (c2 < 0) return -1; 66 int ret = ((c & 0xff) << 8) | (c2 & 0xff); 67 return ret; 68 } 69 70 public int read(char[] buf, int pos, int len) throws IOException { 71 int cnt = 0; 72 while (cnt < len) { 73 int c = read(); 74 if (c < 0) break; 75 buf[pos + (cnt++)] = (char)c; 76 } 77 return cnt; 78 } 79 80 public void close() throws IOException { 81 in.close(); 82 } 83 } 84 | Popular Tags |