Ejemplo n.º 1
0
 void TermBuffer::read(IndexInputPtr input, FieldInfosPtr fieldInfos)
 {
     this->term.reset(); // invalidate cache
     int32_t start = input->readVInt();
     int32_t length = input->readVInt();
     int32_t totalLength = start + length;
     if (preUTF8Strings)
         text->setLength(start + input->readChars(text->result.get(), start, length));
     else
     {
         StringUtils::toUTF8(text->result.get(), text->length, bytes);
         bytes->setLength(totalLength);
         input->readBytes(bytes->result.get(), start, length);
         StringUtils::toUnicode(bytes->result.get(), totalLength, text);
     }
     this->field = fieldInfos->fieldName(input->readVInt());
 }
void checkReadBytes(IndexInputPtr input, int32_t size, int32_t pos)
{
    // Just to see that "offset" is treated properly in readBytes(), we add an arbitrary offset at 
    // the beginning of the array
    int32_t offset = size % 10; // arbitrary
    ByteArray buffer(ByteArray::newInstance(10));
    buffer.resize(MiscUtils::getNextSize(offset + size));
    BOOST_CHECK_EQUAL(pos, input->getFilePointer());
    int64_t left = TEST_FILE_LENGTH - input->getFilePointer();
    if (left <= 0)
        return;
    else if (left < size)
        size = (int32_t)left;
    input->readBytes(buffer.get(), offset, size);
    BOOST_CHECK_EQUAL(pos + size, input->getFilePointer());
    for (int32_t i = 0; i < size; ++i)
        BOOST_CHECK_EQUAL(byten(pos + i), buffer[offset + i]);
}
 virtual void readBytes(uint8_t* b, int32_t offset, int32_t length) {
     input->readBytes(b, offset, length);
 }