📄 request.java
字号:
if (r.read() != -1) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "The specified size of the Reader, parameter #" + parameterIndex + ", is less than the actual InputStream length")); } } catch (java.io.IOException e) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, e, "Encountered error in stream length verification for Reader, parameter #" + parameterIndex + ". Message: " + e.getMessage())); } } else { //data stream encryption byte[] lengthAndCodepoint; lengthAndCodepoint = buildLengthAndCodePointForEncryptedLob(codePoint, leftToRead, writeNullByte, extendedLengthByteCount); // write the data int charsRead = 0; char[] buf = new char[leftToRead / 2]; byte[] clearedBytes = new byte[leftToRead]; int pos = 0; do { // fill in a half-character if we have one from a previous segment try { // read as many whole characters as needed to fill the buffer // half characters are handled above charsRead = r.read(buf, 0, leftToRead / 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++) { clearedBytes[pos++] = (byte) (buf[i] >>> 8); clearedBytes[pos++] = (byte) (buf[i]); } bytesToRead -= 2 * charsRead; leftToRead -= 2 * charsRead; } while (leftToRead > 0); // check to make sure that the specified length wasn't too small try { if (r.read() != -1) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, "The specified size of the Reader, parameter #" + parameterIndex + ", is less than the actual InputStream length")); } } catch (java.io.IOException e) { netAgent_.accumulateReadException(new SqlException(netAgent_.logWriter_, e, "Encountered error in stream length verification for Reader, 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); int encryptedBytesLength = 0; byte[] encryptedBytes = null; try { EncryptionManager encryptionMgr = netAgent_.netConnection_.getEncryptionManager(); byte[] publicKey = netAgent_.netConnection_.getTargetPublicKey(); encryptedBytes = encryptionMgr.encryptData(newClearedBytes, NetConfiguration.SECMEC_EUSRIDPWD, publicKey, publicKey); encryptedBytesLength = encryptedBytes.length; } catch (Exception e) { e.printStackTrace(); } 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) { 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; } } } } // prepScalarStream does the following prep for writing stream data: // 1. Flushes an existing DSS segment, if necessary // 2. Determines if extended length bytes are needed // 3. Creates a new DSS/DDM header and a null byte indicator, if applicable protected final int prepScalarStream(boolean chained, boolean chainedWithSameCorrelator, boolean writeNullByte, int leftToRead) throws DisconnectException { int extendedLengthByteCount; int nullIndicatorSize = 0; if (writeNullByte) { // leftToRead is cast to (long) on the off chance that +4+1 pushes it outside the range of int extendedLengthByteCount = calculateExtendedLengthByteCount((long) leftToRead + 4 + 1); nullIndicatorSize = 1; } else { extendedLengthByteCount = calculateExtendedLengthByteCount(leftToRead + 4); } // flush the existing DSS segment if this stream will not fit in the send buffer // leftToRead is cast to (long) on the off chance that +4+1 pushes it outside the range of int if (10 + extendedLengthByteCount + nullIndicatorSize + (long) leftToRead + offset_ > DssConstants.MAX_DSS_LEN) { try { if (simpleDssFinalize) { finalizeDssLength(); } else { finalizePreviousChainedDss(true); } sendBytes(netAgent_.getOutputStream()); } catch (java.io.IOException e) { netAgent_.throwCommunicationsFailure("Request.writeScalarStream(...,InputStream)", "OutputStream.flush()", e.getMessage(), "*"); } } if (netAgent_.netConnection_.getSecurityMechanism() == NetConfiguration.SECMEC_EUSRIDDTA || netAgent_.netConnection_.getSecurityMechanism() == NetConfiguration.SECMEC_EUSRPWDDTA) { buildDss(true, chained, chainedWithSameCorrelator, DssConstants.GDSFMT_ENCOBJDSS, correlationID_, true); } else // buildDss should not call ensure length. { buildDss(true, chained, chainedWithSameCorrelator, DssConstants.GDSFMT_OBJDSS, correlationID_, true); } return extendedLengthByteCount; } // Writes out a scalar stream DSS segment, along with DSS continuation headers, // if necessary. protected final int flushScalarStreamSegment(int leftToRead, int bytesToRead) throws DisconnectException { int newBytesToRead = bytesToRead; // either at end of data, end of dss segment, or both. if (leftToRead != 0) { // 32k segment filled and not at end of data. if ((Utils.min(2 + leftToRead, 32767)) > (bytes_.length - offset_)) { try { sendBytes(netAgent_.getOutputStream()); } catch (java.io.IOException ioe) { netAgent_.throwCommunicationsFailure("Request.writeScalarStream(...,InputStream)", "OutputStream.flush()", ioe.getMessage(), "*"); } } dssLengthLocation_ = offset_; bytes_[offset_++] = (byte) (0xff); bytes_[offset_++] = (byte) (0xff); newBytesToRead = Utils.min(leftToRead, 32765); } return newBytesToRead; } // the offset_ must not be updated when an error is encountered // note valid data may be overwritten protected final void padScalarStreamForError(int leftToRead, int bytesToRead) throws DisconnectException { do { do { bytes_[offset_++] = (byte) (0x0); // use 0x0 as the padding byte bytesToRead--; leftToRead--; } while (bytesToRead > 0); bytesToRead = flushScalarStreamSegment(leftToRead, bytesToRead); } while (leftToRead > 0); } private final void writeExtendedLengthBytes(int extendedLengthByteCount, long length) { int shiftSize = (extendedLengthByteCount - 1) * 8; for (int i = 0; i < extendedLengthByteCount; i++) { bytes_[offset_++] = (byte) ((length >>> shiftSize) & 0xff); shiftSize -= 8; } } private final byte[] writeExtendedLengthBytesForEncryption(int extendedLengthByteCount, long length) { int shiftSize = (extendedLengthByteCount - 1) * 8; byte[] extendedLengthBytes = new byte[extendedLengthByteCount]; for (int i = 0; i < extendedLengthByteCount; i++) { extendedLengthBytes[i] = (byte) ((length >>> shiftSize) & 0xff); shiftSize -= 8; } return extendedLengthBytes; } // experimental lob section - end // used to finialize a dss which is already in the buffer // before another dss is built. this includes updating length // bytes and chaining bits.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -