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 52 public class AsciiReader extends Reader { 53 InputStream in; 54 55 public AsciiReader(InputStream in) { 56 this.in = in; 57 } 58 59 public void close() throws IOException { 60 in.close(); 61 } 62 63 public int read() throws IOException { 64 return in.read(); 65 } 66 67 public int read(char[] cbuf) throws IOException { 68 for (int i = 0; i < cbuf.length; i++) { 69 int c = read(); 70 if (c < 0) return i; 71 cbuf[i] = (char)c; 72 } 73 return cbuf.length; 74 } 75 76 public int read(char[] cbuf, int off, int len) throws IOException { 77 for (int i = 0; i < len; i++) { 78 int c = read(); 79 if (c < 0) return i; 80 cbuf[off + i] = (char)c; 81 } 82 return len; 83 } 84 } 85 | Popular Tags |