public void compressedAndSend(int notCompressPosition,byte[] bufferBytes,boolean logQuery) throws IOException {
  int position=0;
  int packetLength;
  while (position - notCompressPosition < 0) {
    packetLength=Math.min(notCompressPosition - position,maxPacketSize);
    boolean compressedPacketSend=false;
    if (packetLength > MIN_COMPRESSION_SIZE) {
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      DeflaterOutputStream deflater=new DeflaterOutputStream(baos);
      deflater.write(bufferBytes,position,packetLength);
      deflater.finish();
      deflater.close();
      byte[] compressedBytes=baos.toByteArray();
      baos.close();
      if (compressedBytes.length < (int)(MIN_COMPRESSION_RATIO * packetLength)) {
        int compressedLength=compressedBytes.length;
        writeCompressedHeader(compressedLength,packetLength);
        if (logger.isTraceEnabled() && logQuery) {
          logger.trace("send packet seq:" + compressSeqNo + " length:"+ packetLength+ " data:"+ Utils.hexdump(compressedBytes,maxQuerySizeToLog));
        }
        outputStream.write(compressedBytes,0,compressedLength);
        compressedPacketSend=true;
      }
    }
    if (!compressedPacketSend) {
      writeCompressedHeader(packetLength,0);
      if (logger.isTraceEnabled() && logQuery) {
        logger.trace("send packet seq:" + compressSeqNo + " length:"+ packetLength+ " data:"+ Utils.hexdump(bufferBytes,maxQuerySizeToLog,position,packetLength));
      }
      outputStream.write(bufferBytes,position,packetLength);
    }
    position+=packetLength;
  }
}

public void compressedAndSend ( int notCompressPosition , byte [ ] bufferBytes , boolean logQuery ) throws IOException { int position = 0 ; int packetLength ; while ( position - notCompressPosition < 0 ) { packetLength = Math . min ( notCompressPosition - position , maxPacketSize ) ; boolean compressedPacketSend = false ; if ( packetLength > MIN_COMPRESSION_SIZE ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; DeflaterOutputStream deflater = new DeflaterOutputStream ( baos ) ; deflater . write ( bufferBytes , position , packetLength ) ; deflater . finish ( ) ; deflater . close ( ) ; byte [ ] compressedBytes = baos . toByteArray ( ) ; baos . close ( ) ; if ( compressedBytes . length < ( int ) ( MIN_COMPRESSION_RATIO * packetLength ) ) { int compressedLength = compressedBytes . length ; writeCompressedHeader ( compressedLength , packetLength ) ; if ( logger . isTraceEnabled ( ) && logQuery ) { logger . trace ( "send packet seq:" + compressSeqNo + " length:" + packetLength + " data:" + Utils . hexdump ( compressedBytes , maxQuerySizeToLog ) ) ; } outputStream . write ( compressedBytes , 0 , compressedLength ) ; compressedPacketSend = true ; } } if ( ! compressedPacketSend ) { writeCompressedHeader ( packetLength , 0 ) ; if ( logger . isTraceEnabled ( ) && logQuery ) { logger . trace ( "send packet seq:" + compressSeqNo + " length:" + packetLength + " data:" + Utils . hexdump ( bufferBytes , maxQuerySizeToLog , position , packetLength ) ) ; } outputStream . write ( bufferBytes , position , packetLength ) ; } position += packetLength ; } }
compress datas and send them to database .
