Example #1
0
bool OdtWriter::writeUncompressed(QIODevice* device, const QTextDocument* document)
{
	m_xml.setDevice(device);
	m_xml.setCodec("UTF-8");
	m_xml.setAutoFormatting(true);
	m_xml.setAutoFormattingIndent(1);

	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:office:1.0"), QString::fromLatin1("office"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:style:1.0"), QString::fromLatin1("style"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:text:1.0"), QString::fromLatin1("text"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"), QString::fromLatin1("fo"));

	m_xml.writeStartDocument();
	m_xml.writeStartElement(QString::fromLatin1("office:document"));
	m_xml.writeAttribute(QString::fromLatin1("office:mimetype"), QString::fromLatin1("application/vnd.oasis.opendocument.text"));
	m_xml.writeAttribute(QString::fromLatin1("office:version"), QString::fromLatin1("1.2"));

	writeStyles(document);
	writeAutomaticStyles(document);
	writeBody(document);

	m_xml.writeEndElement();
	m_xml.writeEndDocument();

	return !m_xml.hasError();
}
Example #2
0
void Level::write(std::fstream& stream)
{
	//std::string bGFilename = imageManager->getFileName(backGround.getTexture());
	//int bGFilenameSize = bGFilename.size();

	//stream.write((char*) bGFilenameSize, sizeof(int));
	//stream.write(bGFilename.c_str(), bGFilenameSize);

	stream.write((char*)&bgPosition, sizeof(bgPosition));
	
	backGround.write(stream);

	//std::string gGFilename = imageManager->getFileName(gameGround.getTexture());
	//int gGFilenameSize = gGFilename.size();

	//stream.write((char*) gGFilenameSize, sizeof(int));
	//stream.write(gGFilename.c_str(), gGFilenameSize);

	gameGround.write(stream);

	writeBody(stream);

	stream.write((char*)&size, sizeof(size));

}
Example #3
0
static void
readWriteBody
(
    int  fd,    /* read fd   */
    FILE *out,  /* output fd */
    char *path  /* body path */
)
{
    char    buf[BLOCK_BUF_SIZE];
    ssize_t n;

    memset( buf, 0x00, sizeof( buf ) );
    memset( &n,  0x00, sizeof( n )   );

    for( ;; )
    {
        n = readBody( fd, buf, path );
        if( n == 0 )
        {
            break;
        }

        writeBody( buf, n, out );
    }
}
Example #4
0
QByteArray OdtWriter::writeDocument(const QTextDocument* document)
{
	QByteArray data;
	QBuffer buffer(&data);
	buffer.open(QIODevice::WriteOnly);

	m_xml.setDevice(&buffer);
	m_xml.setCodec("UTF-8");
	m_xml.setAutoFormatting(true);
	m_xml.setAutoFormattingIndent(1);

	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:office:1.0"), QString::fromLatin1("office"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:style:1.0"), QString::fromLatin1("style"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:text:1.0"), QString::fromLatin1("text"));
	m_xml.writeNamespace(QString::fromLatin1("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"), QString::fromLatin1("fo"));

	m_xml.writeStartDocument();
	m_xml.writeStartElement(QString::fromLatin1("office:document-content"));
	m_xml.writeAttribute(QString::fromLatin1("office:version"), QString::fromLatin1("1.2"));

	writeAutomaticStyles(document);
	writeBody(document);

	m_xml.writeEndElement();
	m_xml.writeEndDocument();

	buffer.close();
	return data;
}
void CompressGob::execute() {
	Common::File stk;
	Common::File gobConf;
	uint16 chunkCount;


	Common::Filename inpath(_inputPaths[0].path);

	// We output with .stk extension, if there is no specific out file
	if (_outputPath.empty()) {
		_outputPath = inpath;
	}
	// Open input (config) file
	gobConf.open(inpath, "r");
	// Read the input into memory
	_chunks = readChunkConf(gobConf, inpath, chunkCount);
	gobConf.close();

	_outputPath.setFullName(inpath.getFullName());

	stk.open(_outputPath, "wb");

	// Output in compressed format
	writeEmptyHeader (stk, chunkCount);
	writeBody(&inpath, stk, _chunks);
	rewriteHeader(stk, chunkCount, _chunks);
}
Example #6
0
void L3SupServMessage::write(L3Frame& dest) const
{
	// We override L3Message::write for the transaction identifier.
	size_t l3len = bitsNeeded();
	if (dest.size()!=l3len) dest.resize(l3len);
	size_t wp = 0;
	dest.writeField(wp,mTI,4);
	dest.writeField(wp,PD(),4);
	dest.writeField(wp,MTI(),8);
	writeBody(dest,wp);
}
Example #7
0
void SRCwriter::writeFile() {

    writeHeader();
    writeBody();
    writeFooter();

    ofstream file(url);
    file << header;
    file << body;
    file << footer;
    file.close();
}
Example #8
0
void CertificationReport::makeReport()
{
    const char* headers[] = {
        "ФИО",
        "Дата рождения",
        "Разряд",
        "Тренер",
        "Рег. №",
        "Аттестуется на",
        "Примечание",
    };
    writeBody(headers, sizeof(headers)/sizeof(*headers));
}
Example #9
0
void SportsmenReport::makeReport()
{
    const char *headers[] = {
        "РегНомер",
        "ФИО",
        "Дата рождения",
        "Адрес",
        "Телефон",
        "Место р/уч",
        "Должность",
        "Тренер",
        "Разряд",
    };
    writeBody(headers, sizeof(headers)/sizeof(*headers));
}
void WriteCPlusPlusClass::write(QString path)
{
    for (int i = 0; i < this->mJsonClasses.size(); i++) {
        JsonClass newClass = this->mJsonClasses.at(i);
        QFile file(path + newClass.name + ".h");

        file.open(QIODevice::WriteOnly);

        writeInclude(file, newClass);
        file.close();
        file.setFileName(path + newClass.name + ".cpp");
        file.open(QIODevice::WriteOnly);
        writeBody(file, newClass);
        file.close();
    }
}
Example #11
0
static int sendRequest(HttpConn *conn, cchar *method, cchar *url, MprList *files)
{
    if (httpConnect(conn, method, url, app->ssl) < 0) {
        mprError("Can't process request for \"%s\". %s.", url, httpGetError(conn));
        return MPR_ERR_CANT_OPEN;
    }
    /*  
        This program does not do full-duplex writes with reads. ie. if you have a request that sends and receives
        data in parallel -- http will do the writes first then read the response.
     */
    if (app->bodyData || app->formData || files) {
        if (writeBody(conn, files) < 0) {
            mprError("Can't write body data to \"%s\". %s", url, httpGetError(conn));
            return MPR_ERR_CANT_WRITE;
        }
    }
    mprAssert(!mprGetCurrentThread()->yielded);
    httpFinalize(conn);
    return 0;
}
	void SonicXNSection::write(File *file) {
		if (!file) {
			Error::addMessage(Error::NULL_REFERENCE, LIBGENS_S06_XNINFO_ERROR_MESSAGE_NULL_FILE);
			return;
		}
		
		head_address = file->getCurrentAddress();
		file->write((void *) header.c_str(), 4);
		file->writeNull(4);

		writeBody(file);

		file->fixPadding(LIBGENS_XNSECTION_PADDING);
		size_t bookmark=file->getCurrentAddress();

		
		section_size = bookmark - head_address - LIBGENS_XNSECTION_HEADER_SIZE;
		file->goToAddress(head_address + 4);
		file->writeInt32(&section_size);


		file->goToAddress(bookmark);
	}
Example #13
0
static int doRequest(MprHttp *http, cchar *url, MprList *fields, MprList *files)
{
    MprHttpResponse *resp;
    MprKeyValue     *header;
    char            buf[MPR_HTTP_BUFSIZE], seqBuf[16], *responseHeaders, *redirect;
    int64           contentLen;
    int             code, next, count, bytes, transCount;

    mprAssert(url && *url);

    mprLog(http, MPR_DEBUG, "fetch: %s %s", method, url);

    /*
     *  Send the request
     */
    count = -1;
    transCount = 0;
    do {
        for (next = 0; (header = mprGetNextItem(headers, &next)) != 0; ) {
            mprSetHttpHeader(http, 0, header->key, header->value);
        }
        if (sequence) {
            static int next = 0;
            mprItoa(seqBuf, sizeof(seqBuf), next++, 10);
            mprSetHttpHeader(http, 1, "X-Http-Seq", seqBuf);
        }
        if (ranges) {
            mprSetHttpHeader(http, 1, "Range", ranges);
        }
        if (fields) {
            mprSetHttpHeader(http, 1, "Content-Type", "application/x-www-form-urlencoded");
        }
        if (chunkSize) {
            mprSetHttpChunked(http, 1);
        }
        if (setContentLength(http, fields, files) < 0) {
            return MPR_ERR_CANT_OPEN;
        }
        if (mprStartHttpRequest(http, method, url) < 0) {
            mprError(http, "Can't process request for \"%s\". %s", url, mprGetHttpError(http));
            return MPR_ERR_CANT_OPEN;
        }
        /*
         *  This program does not do full-duplex writes with reads. ie. if you have a request that sends and receives
         *  data in parallel -- http will do the writes first then read the response.
         */
        if (files || fields) {
            if (writeBody(http, fields, files) < 0) {
                mprError(http, "Can't write body data to \"%s\". %s", url, mprGetHttpError(http));
                return MPR_ERR_CANT_WRITE;
            }
        } else {
            if (chunkSize) {
                mprFinalizeHttpWriting(http);
            }
            mprWaitForHttpResponse(http, -1);
        }
#if WIN
        _setmode(fileno(stdout), O_BINARY);
#endif
        while ((bytes = mprReadHttp(http, buf, sizeof(buf))) > 0) {
            showOutput(http, buf, bytes);
        }
        mprWaitForHttp(http, MPR_HTTP_STATE_COMPLETE, -1);
        /* May not be complete if a disconnect occurs */
        if (http->state >= MPR_HTTP_STATE_CONTENT) {
            if (mprNeedHttpRetry(http, &redirect)) {
                if (redirect) {
                    url = resolveUrl(http, redirect);
                }
                count--;
                transCount++;
                continue;
            }
            break;
        }
    } while (++count < http->retries && transCount < 4 && !mprIsExiting(http));

    if (count >= http->retries) {
        mprError(http, "http: failed \"%s\" request for %s after %d attempt(s)", method, url, count);
        return MPR_ERR_TOO_MANY;
    }
    if (mprIsExiting(http)) {
        return MPR_ERR_BAD_STATE;
    }

    /*
     *  Request now complete
     */
    code = mprGetHttpCode(http);
    contentLen = mprGetHttpContentLength(http);

    mprLog(http, 6, "Response code %d, content len %d", code, contentLen);

    if (http->response) {
        if (showCode) {
            mprPrintf(http, "%d\n", code);
        }
        if (showHeaders) {
            responseHeaders = mprGetHttpHeaders(http);
            resp = http->response;
            mprPrintf(http, "%s %d %s\n", resp->protocol, resp->code, resp->message);
            mprPrintf(http, "%s\n", responseHeaders);
            mprFree(responseHeaders);
        }
    }

    if (code < 0) {
        mprError(http, "Can't process request for \"%s\" %s", url, mprGetHttpError(http));
        return MPR_ERR_CANT_READ;

    } else if (code == 0 && http->protocolVersion == 0) {
        ;

    } else if (!(200 <= code && code <= 206) && !(301 <= code && code <= 304)) {
        if (!showCode) {
            mprError(http, "Can't process request for \"%s\" (%d) %s", url, code, mprGetHttpError(http));
            return MPR_ERR_CANT_READ;
        }
    }

    lock();
    if (verbose && noout) {
        trace(http, url, fetchCount, method, code, (int) contentLen);
    }
    unlock();
    return 0;
}