Ejemplo n.º 1
0
void CodaSignalHandler::handleFileSystemRead(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply || result.values.size() != 2) {
        reportError(tr("Could not read remote file: %1").arg(result.errorString()));
        return;
    }

    QByteArray data = QByteArray::fromBase64(result.values.at(0).data());
    bool eof = result.values.at(1).toVariant().toBool();
    qint64 written = d->localFile->write(data);
    if (written < 0) {
        reportError(tr("Could not write data to host file: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
        return;
    }

    d->remoteBytesLeft -= written;
    if (!eof && d->remoteBytesLeft > 0) {
        readNextChunk();
    }
    else {
        d->localFile->flush();
        d->localFile->close();
        closeFile();
    }
}
Ejemplo n.º 2
0
void CacheResult::writeToFileImpl()
{
    m_bufferSize = m_entry->GetDataSize(kResponseContentIndex);
    m_readOffset = 0;
    m_wasWriteToFileSuccessful = false;
    readNextChunk();
}
Ejemplo n.º 3
0
char InputWrapper::nextChar()
{
	char next = buf[bufPosition];
	bufPosition++;
	if(bufPosition == buf.size())
		readNextChunk();

	return next;
}
Ejemplo n.º 4
0
/**
 * Start downloading data.
 */
void HighLevelReaderThatReadsChunks::startRecvToData()
{
    // Content length is unknown, read data in chunks until we get
    // CONNERR_CLOSED.
    bool success = readNextChunk();
    if (!success)
    {
        mConnection->downloadError(RES_OUT_OF_MEMORY);
    }
}
Ejemplo n.º 5
0
bool CSLStatement::buildStatement( const string& stmt )
{
	if (stmt.length() == 0)
		return false;

	cout << endl << "<ul>" << endl << endl;
	cout << "<li><b>Base: " << stmt << "</b></li>" << endl;

	string tmp = stmt;
	while (tmp.length() > 0)
	{
		tmp = readNextChunk(tmp);
	}

	cout << endl << "</ul>" << endl << endl;

	return false;
}
Ejemplo n.º 6
0
void CacheResult::onReadNextChunkDone(int size)
{
    if (size > 0) {
        // Still more reading to be done.
        if (writeChunkToFile()) {
            // TODO: I assume that we need to clear and resize the buffer for the next read?
            m_readOffset += size;
            m_bufferSize -= size;
            readNextChunk();
        } else
            onWriteToFileDone();
        return;
    }

    if (!size) {
        // Reached end of file.
        if (writeChunkToFile())
            m_wasWriteToFileSuccessful = true;
    }
    onWriteToFileDone();
}
Ejemplo n.º 7
0
void CodaSignalHandler::handleFileSystemStart(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        reportError(tr("Could not open remote file: %1").arg(result.errorString()));
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).children().isEmpty()) {
        reportError(tr("Could not get file attributes"));
        return;
    }

    Coda::JsonValue val = result.values.at(0).findChild("Size");
    d->remoteFileSize = val.isValid() ? val.data().toLong() : -1L;
    if (d->remoteFileSize < 0) {
        reportError(tr("Could not get file size"));
        return;
    }

    d->remoteBytesLeft = d->remoteFileSize;
    readNextChunk();
}
Ejemplo n.º 8
0
/**
 * Called when the new data is available.
 */
void HighLevelReaderThatReadsChunks::connRecvFinished(int result)
{
    // If the connection is closed we have completed reading the data.
    if (CONNERR_CLOSED == result)
    {
        finishedDownloadingChunkedData();
        return;
    }

    // Have we got an error?
    if (result <= 0)
    {
        mConnection->downloadError(result);
        return;
    }

    // We have new data.
    mDataChunkOffset += result;
    mContentLength += result;
    int leftToRead = mDataChunkSize - mDataChunkOffset;

    if (leftToRead > 0)
    {
        // Read more data into current chunk.
        int currentChunkIndex = mDataChunks.size() - 1;
        MAHandle chunk = mDataChunks[currentChunkIndex];
        mConnection->recvToData(chunk, mDataChunkOffset, leftToRead);
    }
    else
    {
        // Read next chunk.
        bool success = readNextChunk();
        if (!success)
        {
            mConnection->downloadError(RES_OUT_OF_MEMORY);
        }
    }
}
Ejemplo n.º 9
0
bool 
OMXMLReaderExpat::next()
{
    TRACE("OMXMLReaderExpat::next");

    if (_status == false)
    {
        return _status;
    }

    while (_status && nextEvent() == NONE)
    {
        if (!_readNextChunk)
        {
            int ret = XML_ResumeParser(_parser);

            if (ret == XML_STATUS_ERROR)
            {
                XML_Error errorCode = XML_GetErrorCode(_parser);
                if (errorCode == XML_ERROR_NOT_SUSPENDED)
                {
                    XML_ParsingStatus pStatus;
                    XML_GetParsingStatus(_parser, &pStatus);
                    if (pStatus.parsing == XML_FINISHED)
                    {
                        // finished
                        _status = false;
                    }
                    else
                    {
                        _readNextChunk = true;
                    }
                }
                else
                {
                    throw OMException(getErrorString());
                }
            }
        }

        if (_readNextChunk)
        {
            void* buffer = XML_GetBuffer(_parser, READ_CHUNK_SIZE);
            _numInBuffer = readNextChunk(buffer, READ_CHUNK_SIZE);

            int ret = XML_ParseBuffer(_parser, _numInBuffer, _numInBuffer < READ_CHUNK_SIZE);

            if (ret == XML_STATUS_ERROR)
            {
                throw OMException(getErrorString());
            }

            if (_status)
            {
                XML_ParsingStatus pStatus;
                XML_GetParsingStatus(_parser, &pStatus);
                if (pStatus.parsing == XML_FINISHED)
                {
                    if (_numInBuffer < READ_CHUNK_SIZE)
                    {
                        _status = false;
                    }
                    else
                    {
                        _readNextChunk = true;
                    }
                }
                else
                {
                    _readNextChunk = false;
                }
            }
        }
    }
    
    return _status;
}