1 package com.quadcap.io; 2 3 40 41 import java.io.IOException ; 42 import java.io.InputStream ; 43 import java.io.Reader ; 44 45 50 public class InputStreamReader extends Reader { 51 InputStream in; 52 53 public InputStreamReader(InputStream in) { 54 this.in = in; 55 } 56 57 public void close() throws IOException { 58 in.close(); 59 } 60 61 public int read() throws IOException { 62 int c1 = in.read(); 63 if (c1 < 0) return -1; 64 int c2 = in.read(); 65 if (c2 < 0) return -1; 66 return ((c1 & 0xff) << 8) | (c2 & 0xff); 67 } 68 69 public int read(char[] cbuf) throws IOException { 70 for (int i = 0; i < cbuf.length; i++) { 71 int c = read(); 72 if (c < 0) return i; 73 cbuf[i] = (char)c; 74 } 75 return cbuf.length; 76 } 77 78 public int read(char[] cbuf, int off, int len) throws IOException { 79 for (int i = 0; i < len; i++) { 80 int c = read(); 81 if (c < 0) return i; 82 cbuf[off + i] = (char)c; 83 } 84 return len; 85 } 86 } 87 | Popular Tags |