Beispiel #1
0
  public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter)
      throws SQLException {
    try {
      int bidiStringType = settings_.getBidiStringType();
      // if bidiStringType is not set by user, use ccsid to get value
      if (bidiStringType == -1) bidiStringType = ccsidConverter.bidiStringType_;

      BidiConversionProperties bidiConversionProperties =
          new BidiConversionProperties(bidiStringType);
      bidiConversionProperties.setBidiImplicitReordering(settings_.getBidiImplicitReordering());
      bidiConversionProperties.setBidiNumericOrderingRoundTrip(settings_.getBidiNumericOrdering());

      // The length in the first 2 bytes is actually the length in characters.
      byte[] temp = ccsidConverter.stringToByteArray(value_, bidiConversionProperties);
      BinaryConverter.unsignedShortToByteArray(temp.length, rawBytes, offset);
      if (temp.length > maxLength_) {
        maxLength_ = temp.length;
        JDError.throwSQLException(this, JDError.EXC_INTERNAL);
      }
      System.arraycopy(temp, 0, rawBytes, offset + 2, temp.length);

      // The buffer we are filling with data is big enough to hold the entire field.
      // For varchar fields the actual data is often smaller than the field width.
      // That means whatever is in the buffer from the previous send is sent to the
      // system.  The data stream includes actual data length so the old bytes are not
      // written to the database, but the junk left over may decrease the affectiveness
      // of compression.  The following code will write hex 0s to the buffer when
      // actual length is less that field length.  Note the 0s are written only if
      // the field length is pretty big.  The data stream code (DBBaseRequestDS)
      // does not compress anything smaller than 1K.
      if ((maxLength_ > 256) && (maxLength_ - temp.length > 16)) {
        int stopHere = offset + 2 + maxLength_;
        for (int i = offset + 2 + temp.length; i < stopHere; i++) rawBytes[i] = 0x00;
      }
    } catch (Exception e) {
      JDError.throwSQLException(this, JDError.EXC_INTERNAL, e);
    }
  }
Beispiel #2
0
 public void convertToRawBytes(byte[] rawBytes, int offset, ConvTable ccsidConverter)
     throws SQLException {
   AS400ByteArray typeConverter = new AS400ByteArray(length_);
   BinaryConverter.unsignedShortToByteArray(length_, rawBytes, offset);
   typeConverter.toBytes(value_, rawBytes, offset + 2);
 }