예제 #1
0
void XMLDocumentWrapper::parseFile(const std::string& sFile)
{
    BinaryFile bf;
    bf.open(sFile, BinaryFile::READ);

    size_t len = (size_t)bf.getLength();
    char* buf = m_doc.allocate_string(NULL, len + 1);
    buf[len] = 0;
    try
    {
        bf.read(buf, len);
    }
    catch (const FileIOException& fe)
    {
        bf.close();
        clear();
        FIRTEX_RETHROW(fe);
    }	
    bf.close();

    try 
    {
        m_doc.parse<rapidxml::parse_full>(buf);
    }
    catch(rapidxml::parse_error& e)
    {
        clear();
        FIRTEX_THROW(BadXmlFormatException, "Bad xml format: [%s]", e.what());
    }
}
예제 #2
0
    void index(const tstring& sDir)
    {
        IndexWriterPtr pIndexWriter = m_pIndex->acquireWriter();

        DirectoryIterator di(sDir, false);
        while(di.hasNext())
        {
            const File& f = di.next();
            if(f.isFile())
            {
                BinaryFile bf;
                bf.open(f.getPath().c_str(), BinaryFile::READ);
                if(bf.isFileOpen())
                {
                    size_t nRead = (size_t)bf.getLength();
                    if (nRead > 0)
                    {
                        DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema());
                        pDoc->addField(0, f.getPath().c_str());
                        char* buf = new char[nRead + 1];
                        bf.read(buf, nRead);
                        buf[nRead] = 0;
                        pDoc->addField(1, buf, nRead, false);
                        delete[] buf;
                        
                        pIndexWriter->addDocument(pDoc);
                    }
                }
            }
        }
        docPool.commit();
        pIndexWriter->close();
    }
예제 #3
0
void BinaryFileTestCase::testSeek()
{
	tstring str = TestHelper::getTestDataPath(_T("BinaryFileTestSeek"), false);
	BinaryFile fileWriter;
    fileWriter.open(str, BinaryFile::CREATE);
	CPPUNIT_ASSERT( fileWriter.isFileOpen() );
	int32_t nData;
	for(size_t i = 0; i < 1000; ++i)
	{
        nData = (int32_t)i;
		fileWriter.write(&nData, sizeof(int32_t));
	}
	fileWriter.close();

	BinaryFile fileReader;
    fileReader.open(str, BinaryFile::READ);
	CPPUNIT_ASSERT( fileReader.isFileOpen() );
	CPPUNIT_ASSERT((int64_t)1000 * sizeof(int32_t) == fileReader.getLength());

	CPPUNIT_ASSERT_EQUAL((int64_t)0, fileReader.getPos());
    fileReader.seek(10);
	CPPUNIT_ASSERT_EQUAL((int64_t)10, fileReader.getPos());

    fileReader.close();
    
    //Remove file
    File f(str);
    f.remove();
}
예제 #4
0
bool ProgAlgSram::ProgramSram(BinaryFile &file, Sram_Options_t options)
{
    struct timeval tv[2];
    bool verbose=io->getVerbose();
    gettimeofday(tv, NULL);

    // Switch to USER1 register, to access BSCAN..
    jtag->shiftIR(&USER1,0);

    if(options==FULL||options==WRITE_ONLY)
    {
        printf("\nProgramming SRAM\n");
        if(!Sram_Write(file.getData(), file.getLength(), verbose))
            return false;
    }

    if(options==FULL||options==VERIFY_ONLY)
    {
        printf("\nVerifying SRAM\n");
        if(!Sram_Verify(file.getData(), file.getLength(), verbose))
            return false;
    }

    if (verbose)
    {
        gettimeofday(tv+1, NULL);
        printf("\nTotal SRAM execution time %.1f ms\n", (double)deltaT(tv, tv + 1)/1.0e3);
    }

    /* JPROGAM: Trigerr reconfiguration, not explained in ug332, but
     DS099 Figure 28:  Boundary-Scan Configuration Flow Diagram (p.49) */
    if(options==FULL)
    {
        jtag->shiftIR(&JPROGRAM);
        Sleep(1000);//just wait a bit to make sure everything is done..
    }

    jtag->shiftIR(&BYPASS);

  return true;
}
예제 #5
0
void HTMLParser::parse(const tstring& sHtmlFile)
{
    BinaryFile bf;
    try
    {
        bf.open(sHtmlFile, BinaryFile::READ);
    
        m_nFileSize = (size_t)bf.getLength();
        if(m_nFileSize > MAX_FILESIZE - 1)
        {
            m_nFileSize = MAX_FILESIZE - 1;
        }

        if(!m_pReadBuffer)
        {
            m_nReadBufferSize = DEFAULT_READBUFFER_SIZE;
            if(m_nReadBufferSize < m_nFileSize + 1)
                m_nReadBufferSize = m_nFileSize + 1;
            m_pReadBuffer = new char[m_nReadBufferSize];
        }
        else if(m_nFileSize + 1 > m_nReadBufferSize)
        {
            m_nReadBufferSize = m_nFileSize + 1;
            delete[] m_pReadBuffer;
            m_pReadBuffer = new char[m_nReadBufferSize];
        }
        size_t nRet = bf.read(m_pReadBuffer, m_nFileSize);
        if(nRet != m_nFileSize)
        {
            FX_LOG(WARN, "Read file [%s] error", sHtmlFile.c_str());
            bf.close();
            return;
        }
        bf.close();
        parse(m_pReadBuffer, m_nFileSize);
    }
    catch(const FirteXException& e)
    {
        FX_LOG(ERROR, "Parse file: [%s] FAILED. Error message: [%s]",
               sHtmlFile.c_str(), e.what().c_str());
    }
}