home *** CD-ROM | disk | FTP | other *** search
- package sun.jdbc.odbc;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.SQLException;
- import java.sql.Statement;
-
- public class JdbcOdbcInputStream extends InputStream {
- protected JdbcOdbc OdbcApi;
- protected int hStmt;
- protected int column;
- protected short type;
- public static final short ASCII = 1;
- public static final short UNICODE = 2;
- public static final short BINARY = 3;
- public static final short LOCAL = 4;
- protected byte[] localByteArray;
- protected int localOffset;
- protected boolean invalid;
- protected boolean highRead;
- protected int sqlType;
- protected byte[] buf;
- public static final int MAX_BUF_LEN = 5120;
- protected int convertType;
- public static final int CONVERT_NONE = 0;
- public static final int CONVERT_UNICODE = 1;
- public static final int CONVERT_ASCII = 2;
- public static final int CONVERT_BOTH = 3;
- protected int convertMultiplier;
- protected int bytesInBuf;
- protected int bufOffset;
- protected Statement ownerStatement;
-
- public JdbcOdbcInputStream(JdbcOdbc var1, int var2, int var3, short var4, int var5, Statement var6) {
- this.OdbcApi = var1;
- this.hStmt = var2;
- this.column = var3;
- this.type = var4;
- this.invalid = false;
- this.ownerStatement = var6;
- this.sqlType = -2;
- switch (var5) {
- case -1:
- case 1:
- case 12:
- this.sqlType = 1;
- default:
- this.convertMultiplier = 1;
- this.convertType = 0;
- switch (this.type) {
- case 1:
- if (this.sqlType == -2) {
- this.convertMultiplier = 2;
- this.convertType = 2;
- }
- break;
- case 2:
- if (this.sqlType == -2) {
- this.convertType = 3;
- this.convertMultiplier = 4;
- } else {
- this.convertType = 1;
- this.convertMultiplier = 2;
- }
- }
-
- this.buf = new byte[5120 * this.convertMultiplier];
- this.bytesInBuf = 0;
- this.bufOffset = 0;
- }
- }
-
- public JdbcOdbcInputStream(JdbcOdbc var1, int var2, int var3, byte[] var4) {
- this.OdbcApi = var1;
- this.hStmt = var2;
- this.column = var3;
- this.type = 4;
- this.localByteArray = var4;
- this.localOffset = 0;
- this.invalid = false;
- }
-
- public int read() throws IOException {
- byte[] var2 = new byte[1];
- int var1 = this.read(var2);
- if (var1 != -1) {
- var1 = var2[0];
- }
-
- return var1;
- }
-
- public int read(byte[] var1) throws IOException {
- if (var1.length == 0) {
- return -1;
- } else {
- int var2 = 0;
- if (this.invalid) {
- throw new IOException("InputStream is no longer valid - the Statement has been closed, or the cursor has been moved");
- } else {
- switch (this.type) {
- case 4:
- var2 = var1.length;
- if (this.localOffset + var2 > this.localByteArray.length) {
- var2 = this.localByteArray.length - this.localOffset;
- }
-
- if (var2 == 0) {
- var2 = -1;
- } else {
- for(int var3 = 0; var3 < var2; ++var3) {
- var1[var3] = this.localByteArray[this.localOffset + var3];
- }
-
- this.localOffset += var2;
- }
- break;
- default:
- var2 = this.readData(var1);
- }
-
- return var2;
- }
- }
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- throw new IOException("Method not implemented");
- }
-
- public int available() throws IOException {
- throw new IOException();
- }
-
- public void invalidate() {
- this.invalid = true;
- }
-
- protected int readData(byte[] var1) throws IOException {
- int var2 = -1;
- int var3 = 0;
-
- while(this.bytesInBuf != -1 && var3 < var1.length) {
- if (this.bufOffset >= this.bytesInBuf) {
- this.bytesInBuf = this.readBinaryData(this.buf, 5120);
- this.bytesInBuf = this.convertData(this.buf, this.bytesInBuf);
- this.bufOffset = 0;
- } else {
- var1[var3] = this.buf[this.bufOffset];
- ++var3;
- ++this.bufOffset;
- }
- }
-
- if (var3 > 0) {
- var2 = var3;
- }
-
- return var2;
- }
-
- protected int readBinaryData(byte[] var1, int var2) throws IOException {
- int var3 = 0;
-
- try {
- var3 = this.OdbcApi.SQLGetDataBinary(this.hStmt, this.column, -2, var1, var2);
- } catch (JdbcOdbcSQLWarning var6) {
- Integer var5 = (Integer)var6.value;
- var3 = var5;
- } catch (SQLException var7) {
- throw new IOException(((Throwable)var7).getMessage());
- }
-
- return var3;
- }
-
- protected int convertData(byte[] var1, int var2) {
- if (this.convertType == 0) {
- return var2;
- } else {
- String var3 = "0123456789ABCDEF";
- if (var2 <= 0) {
- return var2;
- } else {
- for(int var4 = var2 - 1; var4 >= 0; --var4) {
- if (this.convertType == 3) {
- var1[var4 * 4 + 3] = (byte)var3.charAt(var1[var4] & 15);
- var1[var4 * 4 + 2] = 0;
- var1[var4 * 4 + 1] = (byte)var3.charAt(var1[var4] >> 4 & 15);
- var1[var4 * 4] = 0;
- } else if (this.convertType == 2) {
- var1[var4 * 2 + 1] = (byte)var3.charAt(var1[var4] & 15);
- var1[var4 * 2] = (byte)var3.charAt(var1[var4] >> 4 & 15);
- } else {
- var1[var4 * 2 + 1] = var1[var4];
- var1[var4 * 2] = 0;
- }
- }
-
- return var2 * this.convertMultiplier;
- }
- }
- }
- }
-