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.SQLWarning;
- 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] & 255;
- }
-
- return var1;
- }
-
- public int read(byte[] var1) throws IOException {
- return this.read(var1, 0, var1.length);
- }
-
- public byte[] readAllData() throws IOException {
- int var1 = 0;
- if (this.invalid) {
- throw new IOException("InputStream is no longer valid - the Statement has been closed, or the cursor has been moved");
- } else {
- byte[] var2;
- switch (this.type) {
- case 4:
- if (this.localOffset + var1 > this.localByteArray.length) {
- var1 = this.localByteArray.length - this.localOffset;
- }
-
- var2 = new byte[this.localByteArray.length];
- if (var1 == 0) {
- var1 = -1;
- } else {
- System.arraycopy(this.localByteArray, this.localOffset, var2, this.localOffset, var1);
- this.localOffset += var1;
- }
- break;
- default:
- var2 = this.readData();
- }
-
- return var2;
- }
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
- if (var3 == 0) {
- return -1;
- } else {
- int var4 = 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:
- var4 = var3;
- if (this.localOffset + var3 > this.localByteArray.length) {
- var4 = this.localByteArray.length - this.localOffset;
- }
-
- if (var4 == 0) {
- var4 = -1;
- } else {
- for(int var5 = var2; var5 < var4; ++var5) {
- var1[var5] = this.localByteArray[this.localOffset + var5];
- }
-
- this.localOffset += var4;
- }
- break;
- default:
- var4 = this.readData(var1, var2, var3);
- }
-
- return var4;
- }
- }
- } else {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public int available() throws IOException {
- throw new IOException();
- }
-
- public void invalidate() {
- this.invalid = true;
- }
-
- public byte[] readData() throws IOException {
- byte[] var1 = null;
- int var2 = 0;
-
- while(true) {
- this.bytesInBuf = this.readBinaryData(this.buf, 5120);
- this.bytesInBuf = this.convertData(this.buf, this.bytesInBuf);
- if (this.bytesInBuf == -1) {
- return var1;
- }
-
- try {
- if (var1 == null) {
- var1 = new byte[this.bytesInBuf];
- } else {
- byte[] var3 = new byte[var2 + this.bytesInBuf];
- System.arraycopy(var1, 0, var3, 0, var2);
- var1 = var3;
- }
- } catch (OutOfMemoryError var4) {
- ((JdbcOdbcStatement)this.ownerStatement).setWarning(new SQLWarning("Data has been truncated. " + ((Throwable)var4).getMessage()));
- return var1;
- }
-
- System.arraycopy(this.buf, 0, var1, var2, this.bytesInBuf);
- var2 += this.bytesInBuf;
- }
- }
-
- protected int readData(byte[] var1, int var2, int var3) throws IOException {
- int var4 = -1;
- int var5 = var2;
-
- while(this.bytesInBuf != -1 && var5 < var3) {
- 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[var5] = this.buf[this.bufOffset];
- ++var5;
- ++this.bufOffset;
- }
- }
-
- if (var5 > var2) {
- var4 = var5;
- }
-
- return var4;
- }
-
- 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;
- }
- }
- }
- }
-