byte[] scratchpad = getScratchpad(); ByteArrayInputStream byteArrayIn = new ByteArrayInputStream(scratchpad); DataInputStream dataIn = new DataInputStream(byteArrayIn);   ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(32); DataOutputStream dataOut = new DataOutputStream(byteArrayOut);    byte[] workBuffer = new byte[32]; int ctr = 0;   dataIn.read(workBuffer, 0, 32);   byte[] columnValueArray = new byte[32]; columnValueArray = inVar.getBytes();   for (ctr = 0; ctr <= 31; ctr++) { if (workBuffer[ctr] != 49) {  if (columnValueArray[ctr] == 49) { workBuffer[ctr] = 49; } else { workBuffer[ctr] = 48; } } }   dataOut.write(workBuffer, 0, 32);   for (ctr = 0; ctr < workBuffer.length; ctr++) { scratchpad[ctr] = workBuffer[ctr]; } setScratchpad(scratchpad);    intermResult = Lob.newBlob(); OutputStream intermOut = intermResult.getOutputStream(); intermOut.write(workBuffer); set(2, intermResult); }
  public void g2_db2_bit_or ( String inVar,                          Blob intermResult )  throws Exception  {    // Test for SQL NULLs in the input parameters and    // the structured value itself    if (isNull(1))    {        return;    }    // variables to read from SCRATCHPAD area    byte[] scratchpad = getScratchpad();    ByteArrayInputStream byteArrayIn =            new ByteArrayInputStream(scratchpad);    DataInputStream dataIn =            new DataInputStream(byteArrayIn);    // variables to write into SCRATCHPAD area    ByteArrayOutputStream byteArrayOut =            new ByteArrayOutputStream(32);    DataOutputStream dataOut =            new DataOutputStream(byteArrayOut);    // Initialize variables    // Byte buffer for the scratchpad copy of the value to be BIT_ORed    byte[] workBuffer = new byte[32];    int ctr = 0;    // Get the current scratchpad into the work buffer    dataIn.read(workBuffer, 0, 32);    // Convert the column value string to an array of bytes    byte[] columnValueArray = new byte[32];    columnValueArray = inVar.getBytes();    // Walk the inVar byte array, test each char.    for (ctr = 0; ctr <= 31; ctr++)    {       if (workBuffer[ctr] != 49)       {          // Check the current column value byte.          if (columnValueArray[ctr] == 49)          // If it's 1 (ASCII 49 = numeric 1),          {             workBuffer[ctr] = 49;                  // then set the corresponding scratchpad bit to 1,          }          else          {             workBuffer[ctr] = 48;                  // else set the corresponding scratchpad bit to 0.          }       }    }    // Write the updated buffer to dataOut    dataOut.write(workBuffer, 0, 32);    // Construct new scratchpad data and store it    for (ctr = 0; ctr < workBuffer.length; ctr++)    {       scratchpad[ctr] = workBuffer[ctr];    }    setScratchpad(scratchpad);    // Set output parameter for new intermediate result    // (VARCHAR FOR BIT DATA is mapped to "Blob" class)    intermResult = Lob.newBlob();    OutputStream intermOut = intermResult.getOutputStream();    intermOut.write(workBuffer);    set(2, intermResult);  }