1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 29 35 36 class AsciiInputStream extends InputStream { 38 private Reader reader; 39 40 public AsciiInputStream(Reader reader) { 41 this.reader = reader; 42 } 43 44 public AsciiInputStream(String s) { 45 this(new StringReader(s)); 46 } 47 48 public int read() throws IOException { 49 int i = reader.read(); 50 if (i == -1) return i; 51 else return (i & 0x0FF); 52 } 53 54 public int read(byte[] b, int off, int len) throws IOException { 55 int end = off + len; 56 int read_count = 0; 57 for (int i = off; i < end; ++i) { 58 int val = read(); 59 if (val == -1) { 60 if (read_count == 0) { 61 return -1; 62 } 63 else { 64 return read_count; 65 } 66 } 67 b[i] = (byte) val; 68 ++read_count; 69 } 70 return read_count; 71 } 72 73 public long skip(long n) throws IOException { 74 return reader.skip(n); 75 } 76 77 public int available() throws IOException { 78 return 0; 80 } 81 82 public void reset() throws IOException { 83 reader.reset(); 84 } 85 86 } 87 | Popular Tags |