Example #1
0
   void _filterMarks( CHAR *pBuff, const CHAR **marks, INT32 num )
   {
      INT32 i = 0 ;
      INT32 left = 0 ;
      CHAR *pos = NULL ;
      CHAR *end = NULL ;

      for ( ; i < num; i++ )
      {
         while( TRUE )
         {
            pos = ossStrstr( pBuff, marks[i] ) ;
            if ( NULL == pos )
            {
               break ;
            }
            end = pos + ossStrlen( marks[i] ) ;
            left = ossStrlen( end ) ;
            ossMemmove( pos, end, left ) ;
            pos[left] = '\0' ;
         }
      }
   }
Example #2
0
   INT32 RecordReader::read(CHAR*& record, INT32& recordLength)
   {
      INT32 rc = SDB_OK;

   readData:
      if (_dataLength <= 0)
      {
         rc = _input->read(_buffer + _remainSize,
                           _bufferSize - _remainSize, _readSize);
         if (SDB_OK != rc)
         {
            if (SDB_EOF != rc)
            {
               PD_LOG(PDERROR, "failed to read from InputStream, rc=%d", rc);
               goto error;
            }

            if (0 == _remainSize)
            {
               // real EOF
               goto done;
            }

            // the final record
            _readSize = 0;
            _final = TRUE;
         }

         _totalSize += _readSize;
         _data = _buffer;
         _dataLength = _remainSize + _readSize;
      }

      rc = _scanner->scan(_data, _dataLength, _final, recordLength);
      if (SDB_OK != rc)
      {
         if (SDB_EOF == rc)
         {
            if (_dataLength > IMP_RECORD_MAX_LENGTH)
            {
               rc = SDB_INVALIDARG;
               PD_LOG(PDERROR, "the remain data is out of length [0-%d]: %d",
                               IMP_RECORD_MAX_LENGTH, _dataLength);
               goto error;
            }
            ossMemmove(_buffer, _data, _dataLength);
            _remainSize = _dataLength;
            _dataLength = 0;
            goto readData;
         }

         PD_LOG(PDERROR, "failed to scan record, rc=%d", rc);
         goto error;
      }

      record = _data;

      if (FORMAT_CSV == _scanner->format())
      {
         _data += (recordLength + _recDelLen);
         _dataLength -= (recordLength + _recDelLen);
      }
      else // JSON
      {
         _data += recordLength;
         _dataLength -= recordLength;
      }

      if (_dataLength <= 0)
      {
         _remainSize = 0;
      }

   done:
      return rc;
   error:
      goto done;
   }