void CvrpFileReader::readData()
{
    while (not m_file->atEnd())
    {
        processNextLine();
    }
}
Exemple #2
0
Task * TextReader::processFile(const QString &url) {
    IOAdapterFactory *iof = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(IOAdapterUtils::url2io(url));
    io = iof->createIOAdapter();
    if(!io->open(url,IOAdapterMode_Read)) {
        return new FailTask(tr("Can't load file %1").arg(url));
    }
    if(actor->getParameter(BaseAttributes::READ_BY_LINES_ATTRIBUTE().getId())->getAttributeValue<bool>(context) == false) {
        QByteArray buf;
        int read = 0;
        int offs = 0;
        buf.resize(READ_BLOCK_SIZE);
        buf.fill(0);
        do {
            read = io->readBlock(buf.data() + offs, READ_BLOCK_SIZE);
            if (read == -1) {
                return new FailTask(tr("Can't load file %1. %2").arg(url).arg(io->errorString()));
            }
            if (read != READ_BLOCK_SIZE) {
                SAFE_POINT(read < READ_BLOCK_SIZE, "Error while reading file", NULL);
                buf.resize(buf.size() - READ_BLOCK_SIZE + read);
                break;
            }
            offs += read;
            buf.resize(offs + READ_BLOCK_SIZE);
        } while(read == READ_BLOCK_SIZE);

        sendMessage(buf);
        io->close();
    } else {
        processNextLine();
    }
    return NULL;
}
Exemple #3
0
Task * TextReader::tick() {
    if(NULL != io && io->isOpen()) {
        processNextLine();
    } else if (urls->hasNext()) {
        url = urls->getNextFile();
        Task *resultTask = processUrlEntity(url);
        if (NULL != resultTask) {
            return resultTask;
        }
    }
    if (!urls->hasNext() && (NULL == io || !io->isOpen())) {
        ch->setEnded();
        setDone();
    }
    return NULL;
}