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