📄 request.java
字号:
//pad it with 0 and encrypt and send it to the server because it takes too much time //can't just throw a SQLException either because some of the data PRPSQLSTT etc have already //been sent to the server, and server is waiting for EXTDTA, server hangs for this. netAgent_.accumulateChainBreakingReadExceptionAndThrow(new org.apache.derby.client.am.DisconnectException(netAgent_, "End of Stream prematurely reached while reading InputStream, parameter #" + parameterIndex + ". ")); return; /*netAgent_.accumulateReadException( new SqlException(netAgent_.logWriter_, "End of Stream prematurely reached while reading InputStream, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0.")); return;*/ } else { pos += bytesRead; //offset_ += bytesRead; //comment this out for data stream encryption. leftToRead -= bytesRead; } } while (leftToRead > 0); // check to make sure that the specified length wasn't too small try { if (in.read() != -1) { // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "The specified size of the InputStream, parameter #" + parameterIndex + ", is less than the actual InputStream length")); } } catch (java.io.IOException e) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "Encountered error in stream length verification for InputStream, parameter #" + parameterIndex + ". Message: " + e.getMessage())); } byte[] newClearedBytes = new byte[clearedBytes.length + lengthAndCodepoint.length]; System.arraycopy(lengthAndCodepoint, 0, newClearedBytes, 0, lengthAndCodepoint.length); System.arraycopy(clearedBytes, 0, newClearedBytes, lengthAndCodepoint.length, clearedBytes.length); //it's wrong here, need to add in the real length after the codepoing 146c byte[] encryptedBytes; encryptedBytes = netAgent_.netConnection_.getEncryptionManager(). encryptData(newClearedBytes, NetConfiguration.SECMEC_EUSRIDPWD, netAgent_.netConnection_.getTargetPublicKey(), netAgent_.netConnection_.getTargetPublicKey()); int encryptedBytesLength = encryptedBytes.length; int sendingLength = bytes_.length - offset_; if (encryptedBytesLength > (bytes_.length - offset_)) { System.arraycopy(encryptedBytes, 0, bytes_, offset_, (bytes_.length - offset_)); offset_ = 32767; try { sendBytes(netAgent_.getOutputStream()); } catch (java.io.IOException ioe) { netAgent_.throwCommunicationsFailure("Request.writeScalarStream(...,InputStream)", "OutputStream.flush()", ioe.getMessage(), "*"); } } else { System.arraycopy(encryptedBytes, 0, bytes_, offset_, encryptedBytesLength); offset_ = offset_ + encryptedBytes.length; } encryptedBytesLength = encryptedBytesLength - sendingLength; while (encryptedBytesLength > 0) { //dssLengthLocation_ = offset_; offset_ = 0; if ((encryptedBytesLength - 32765) > 0) { bytes_[offset_++] = (byte) (0xff); bytes_[offset_++] = (byte) (0xff); System.arraycopy(encryptedBytes, sendingLength, bytes_, offset_, 32765); encryptedBytesLength -= 32765; sendingLength += 32765; offset_ = 32767; try { sendBytes(netAgent_.getOutputStream()); } catch (java.io.IOException ioe) { netAgent_.throwCommunicationsFailure("Request.writeScalarStream(...,InputStream)", "OutputStream.flush()", ioe.getMessage(), "*"); } } else { int leftlength = encryptedBytesLength + 2; bytes_[offset_++] = (byte) ((leftlength >>> 8) & 0xff); bytes_[offset_++] = (byte) (leftlength & 0xff); System.arraycopy(encryptedBytes, sendingLength, bytes_, offset_, encryptedBytesLength); offset_ += encryptedBytesLength; dssLengthLocation_ = offset_; encryptedBytesLength = 0; } } } else //if not data strteam encryption { buildLengthAndCodePointForLob(codePoint, leftToRead, writeNullByte, extendedLengthByteCount); int bytesRead = 0; int totalBytesRead = 0; do { do { try { bytesRead = in.read(bytes_, offset_, bytesToRead); totalBytesRead += bytesRead; } catch (java.io.IOException e) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "Encountered an IOException reading InputStream, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0. Message: " + e.getMessage())); return; } if (bytesRead == -1) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "End of Stream prematurely reached while reading InputStream, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0.")); return; } else { bytesToRead -= bytesRead; offset_ += bytesRead; leftToRead -= bytesRead; } } while (bytesToRead > 0); bytesToRead = flushScalarStreamSegment(leftToRead, bytesToRead); } while (leftToRead > 0); // check to make sure that the specified length wasn't too small try { if (in.read() != -1) { // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "The specified size of the InputStream, parameter #" + parameterIndex + ", is less than the actual InputStream length")); } } catch (java.io.IOException e) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "Encountered error in stream length verification for InputStream, parameter #" + parameterIndex + ". Message: " + e.getMessage())); } } } // Throw DataTruncation, instead of closing connection if input size mismatches // An implication of this, is that we need to extend the chaining model // for writes to accomodate chained write exceptoins final void writeScalarStream(boolean chained, boolean chainedWithSameCorrelator, int codePoint, int length, java.io.Reader r, boolean writeNullByte, int parameterIndex) throws DisconnectException { int leftToRead = length * 2; // the bytes to read int extendedLengthByteCount = prepScalarStream(chained, chainedWithSameCorrelator, writeNullByte, leftToRead); int bytesToRead; if (writeNullByte) { bytesToRead = Utils.min(leftToRead, DssConstants.MAX_DSS_LEN - 6 - 4 - 1 - extendedLengthByteCount); } else { bytesToRead = Utils.min(leftToRead, DssConstants.MAX_DSS_LEN - 6 - 4 - extendedLengthByteCount); } if (netAgent_.netConnection_.getSecurityMechanism() != NetConfiguration.SECMEC_EUSRIDDTA && netAgent_.netConnection_.getSecurityMechanism() != NetConfiguration.SECMEC_EUSRPWDDTA) { buildLengthAndCodePointForLob(codePoint, leftToRead, writeNullByte, extendedLengthByteCount); // write the data int charsRead = 0; boolean haveHalfChar = false; byte halfChar = (byte) 0x0; char[] buf = new char[1 + 32765 / 2]; // enough for one DSS segment do { do { // fill in a half-character if we have one from a previous segment if (haveHalfChar) { bytes_[offset_++] = halfChar; bytesToRead--; leftToRead--; haveHalfChar = false; } if (bytesToRead == 1) { try { charsRead = r.read(buf, 0, 1); } catch (java.io.IOException e) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "Encountered an IOException reading Reader, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0. Message: " + e.getMessage())); return; } if (charsRead == -1) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "End of Stream prematurely reached while reading Reader, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0.")); return; } // set first half-char in buffer and save the other half for later bytes_[offset_++] = (byte) (buf[0] >>> 8); halfChar = (byte) buf[0]; haveHalfChar = true; bytesToRead--; leftToRead--; } else if (bytesToRead != 0) { try { // read as many whole characters as needed to fill the buffer // half characters are handled above charsRead = r.read(buf, 0, bytesToRead / 2); } catch (java.io.IOException e) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, e, "Encountered an IOException reading Reader, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0. Message: " + e.getMessage())); return; } if (charsRead == -1) { padScalarStreamForError(leftToRead, bytesToRead); // set with SQLSTATE 01004: The value of a string was truncated when assigned to a host variable. netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "End of Stream prematurely reached while reading Reader, parameter #" + parameterIndex + ". Remaining data has been padded with 0x0.")); return; } for (int i = 0; i < charsRead; i++) { bytes_[offset_++] = (byte) (buf[i] >>> 8); bytes_[offset_++] = (byte) (buf[i]); } bytesToRead -= 2 * charsRead; leftToRead -= 2 * charsRead; } } while (bytesToRead > 0); bytesToRead = flushScalarStreamSegment(leftToRead, bytesToRead); } while (leftToRead > 0); // check to make sure that the specified length wasn't too small try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -