本文整理汇总了C++中BinaryFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryFile::read方法的具体用法?C++ BinaryFile::read怎么用?C++ BinaryFile::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryFile
的用法示例。
在下文中一共展示了BinaryFile::read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: index
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();
}
示例2: parseFile
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());
}
}
示例3: expFuncRead
ExpressionValue expFuncRead(const std::vector<ExpressionValue>& parameters)
{
ExpressionValue result;
T buffer;
if (parameters[0].isString() == false || (parameters.size() >= 2 && parameters[1].isInt() == false))
{
Logger::queueError(Logger::Error,L"Invalid parameter");
return result;
}
std::wstring fileName = getFullPathName(parameters[0].strValue);
u64 pos = parameters.size() >= 2 ? parameters[1].intValue : 0;
BinaryFile file;
if (file.open(fileName,BinaryFile::Read) == false)
{
Logger::queueError(Logger::Error,L"Could not open %s",fileName);
return result;
}
file.setPos((long)pos);
if (file.read(&buffer,sizeof(T)) == sizeof(T))
{
result.type = ExpressionValueType::Integer;
result.intValue = (u64) buffer;
}
return result;
}
示例4: expFuncRead
ExpressionValue expFuncRead(const std::wstring& funcName, const std::vector<ExpressionValue>& parameters)
{
const std::wstring* fileName;
u64 pos;
GET_PARAM(parameters,0,fileName);
GET_OPTIONAL_PARAM(parameters,1,pos,0);
std::wstring fullName = getFullPathName(*fileName);
BinaryFile file;
if (file.open(fullName,BinaryFile::Read) == false)
{
Logger::queueError(Logger::Error,L"Could not open %s",fileName);
return ExpressionValue();
}
file.setPos((long)pos);
T buffer;
if (file.read(&buffer,sizeof(T)) != sizeof(T))
return ExpressionValue();
return ExpressionValue((u64) buffer);
}
示例5: testRead
void BinaryFileTestCase::testRead()
{
tstring str = TestHelper::getTestDataPath(_T("BinaryFileTestWriteFile"), false);
BinaryFile bf;
bf.open(str.c_str(),BinaryFile::READ);
CPPUNIT_ASSERT( bf.isFileOpen() );
int32_t nData;
for(size_t i = 0; i < 10000;i += 1000)
{
bf.seek(i);
bf.read(&nData,sizeof(int32_t));
CPPUNIT_ASSERT_EQUAL(nData,(int32_t)i);
}
bf.close();
}
示例6: testLargeFileSeekAndRead
void BinaryFileTestCase::testLargeFileSeekAndRead()
{
#ifdef TEST_LARGE_FILE
tstring str = TestHelper::getTestDataPath(_T("BinaryFileTestLargeFile"), false);
BinaryFile bf;
bf.open(str.c_str(), BinaryFile::READ);
CPPUNIT_ASSERT( bf.isFileOpen() );
int64_t nPos = 1000000000;//1 GB
nPos <<= 4;//16 GB
int64_t nData = 123456789;
bf.seek(nPos);
bf.read(&nData,sizeof(int64_t));
CPPUNIT_ASSERT_EQUAL(nData,(int64_t)123456789);
#endif
}
示例7: parse
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());
}
}