1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.Reader ; 28 import java.io.InputStream ; 29 import java.io.IOException ; 30 31 37 38 public final class AsciiReader extends Reader { 39 40 43 private InputStream input; 44 45 48 public AsciiReader(InputStream input) { 49 this.input = input; 50 } 51 52 54 public int read() throws IOException { 55 int v = input.read(); 56 if (v == -1) { 57 return -1; 58 } 59 else { 60 return (char) v; 61 } 62 } 63 64 public int read(char[] buf, int off, int len) throws IOException { 65 if (len < 0) { 66 throw new IOException ("len < 0"); 67 } 68 if (off < 0 || off + len > buf.length) { 69 throw new IOException ("Out of bounds."); 70 } 71 if (len == 0) { 72 return 0; 73 } 74 int read = 0; 75 while (len > 0) { 76 int v = input.read(); 77 if (v == -1) { 78 if (read == 0) { 79 return -1; 80 } 81 else { 82 return read; 83 } 84 } 85 buf[off] = (char) v; 86 ++off; 87 ++read; 88 --len; 89 } 90 return read; 91 } 92 93 public long skip(long n) throws IOException { 94 return input.skip(n); 95 } 96 97 public boolean ready() throws IOException { 98 return false; 99 } 100 101 public void mark(int readAheadLimit) throws IOException { 102 input.mark(readAheadLimit); 103 } 104 105 public void reset() throws IOException { 106 input.reset(); 107 } 108 109 public void close() throws IOException { 110 input.close(); 111 } 112 113 } 114 115 | Popular Tags |