本文整理汇总了C++中FileStream::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::Read方法的具体用法?C++ FileStream::Read怎么用?C++ FileStream::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestMSVCPreprocessedOutput
REGISTER_TESTS_END
// TestMSVCPreprocessedOutput
//------------------------------------------------------------------------------
void TestIncludeParser::TestMSVCPreprocessedOutput() const
{
FileStream f;
TEST_ASSERT( f.Open( "Data/TestIncludeParser/fbuildcore.msvc.ii", FileStream::READ_ONLY) )
const size_t fileSize = (size_t)f.GetFileSize();
AutoPtr< char > mem( (char *)ALLOC( fileSize + 1 ) );
TEST_ASSERT( f.Read( mem.Get(), fileSize ) == fileSize );
mem.Get()[ fileSize ] = 0;
Timer t;
const size_t repeatCount( 100 );
for ( size_t i=0; i<repeatCount; ++i )
{
CIncludeParser parser;
TEST_ASSERT( parser.ParseMSCL_Preprocessed( mem.Get(), fileSize ) );
// check number of includes found to prevent future regressions
const Array< AString > & includes = parser.GetIncludes();
TEST_ASSERT( includes.GetSize() == 284 );
#ifdef DEBUG
TEST_ASSERT( parser.GetNonUniqueCount() == 381 );
#endif
}
float time = t.GetElapsed();
OUTPUT( "MSVC : %2.3fs (%2.1f MiB/sec)\n", time, ( (float)( fileSize * repeatCount / ( 1024.0f * 1024.0f ) ) / time ) );
}
示例2: IOException
LanguagePack * LanguagePack::FromFile(uint16 id, const utf8 * path)
{
assert(path != nullptr);
// Load file directly into memory
utf8 * fileData = nullptr;
try
{
FileStream fs = FileStream(path, FILE_MODE_OPEN);
size_t fileLength = (size_t)fs.GetLength();
if (fileLength > MAX_LANGUAGE_SIZE)
{
throw IOException("Language file too large.");
}
fileData = Memory::Allocate<utf8>(fileLength + 1);
fs.Read(fileData, fileLength);
fileData[fileLength] = '\0';
}
catch (Exception ex)
{
Memory::Free(fileData);
log_error("Unable to open %s: %s", path, ex.GetMessage());
return nullptr;
}
// Parse the memory as text
LanguagePack * result = FromText(id, fileData);
Memory::Free(fileData);
return result;
}
示例3: TestClangMSExtensionsPreprocessedOutput
// TestClangMSExtensionsPreprocessedOutput
//------------------------------------------------------------------------------
void TestIncludeParser::TestClangMSExtensionsPreprocessedOutput() const
{
FBuild fBuild; // needed fer CleanPath for relative dirs
FileStream f;
TEST_ASSERT( f.Open( "Data/TestIncludeParser/fbuildcore.clang.ms-extensions.ii", FileStream::READ_ONLY) )
const size_t fileSize = (size_t)f.GetFileSize();
AutoPtr< char > mem( (char *)ALLOC( fileSize + 1 ) );
TEST_ASSERT( f.Read( mem.Get(), fileSize ) == fileSize );
mem.Get()[ fileSize ] = 0;
Timer t;
const size_t repeatCount( 100 );
for ( size_t i=0; i<repeatCount; ++i )
{
CIncludeParser parser;
TEST_ASSERT( parser.ParseGCC_Preprocessed( mem.Get(), fileSize ) );
// check number of includes found to prevent future regressions
const Array< AString > & includes = parser.GetIncludes();
TEST_ASSERT( includes.GetSize() == 285 );
#ifdef DEBUG
TEST_ASSERT( parser.GetNonUniqueCount() == 4758 );
#endif
}
float time = t.GetElapsed();
OUTPUT( "Clang (ms-extensions): %2.3fs (%2.1f MiB/sec)\n", time, ( (float)( fileSize * repeatCount / ( 1024.0f * 1024.0f ) ) / time ) );
}
示例4: Main
void Test::Main(){
String* path = new String("MyTest.txt");
if (File::Exists(path)){
File::Delete(path);
}
FileStream* fs = File::Create(path);
Test::AddText(fs, new String("This is some text"));
Test::AddText(fs, new String("This is some more text,"));
Test::AddText(fs, new String("\r\nand this is on a new line"));
Test::AddText(fs, new String("\r\n\r\nThe following is a subset of characters:\r\n"));
for (int i = 100; i < 220; i += 1) {
Test::AddText(fs, new String(Convert::ToChar(i)));
if (i % 10 == 0) {
Test::AddText(fs, new String("\r\n"));
}
}
fs->Close();
fs = File::OpenRead(path);
Array<char>* b = new Array<char>(1024);
UTF8Encoding* temp = new UTF8Encoding();
while (fs->Read(b, 0, b->Length) > 0) {
String* s = temp->GetString(b);
Console::WriteLine(s);
}
}
示例5: net_send_file
int DERPEditor::net_send_file(lua_State *L)
{
if (lua_gettop(L) == 1)
{
const char* path = lua_tostring(L, 1);
FileStream s;
if (!s.OpenReadBinary(path))
{
char msg[4096];
//Format(msg, "Could not open file to send (send_file): '%s'", path);
lua_pushstring(L, msg);
lua_error(L);
return 0;
}
unsigned fsize = s.GetSize();
char* data = new char[fsize];
s.Read(data, fsize);
unsigned long hash = Hash(data, fsize);
s.Close();
Packet* packet = LuaApp::GetInstance()->m_net->CreateEmptyPacket("res", 1 /* datacache */);
// hash, filename, datalen, data
packet->PushInt(hash);
const char* filename = PathFileName(path);
packet->PushString(filename, strlen(filename)+1);
packet->PushInt(fsize);
packet->PushString(data, fsize);
Util::Array<Network::Client*>& Clients = LuaApp::GetInstance()->m_net->GetClients();
Util::Array<Network::Client*>::iterator iter = Clients.begin();
while (iter != Clients.end())
{
printf("Sending to client %d.\n", (*iter)->Ident);
(*iter)->SendPacket(packet);
iter++;
}
delete packet;
delete data;
char ret[256];
//Format(ret, "%X_%s", hash, filename);
lua_pushstring(L, ret);
return 1;
}
else
{
lua_pushstring(L, "Invalid arguments passed to send_file function!");
lua_error(L);
}
return 0;
}
示例6: LoadShaderSource
/*!***********************************************************************
@Function LoadShader
@Access public
@Param const char * c_pszName
@Returns bool
@Description
*************************************************************************/
bool ResourceManager::LoadShaderSource(const char* c_pszFilename, Uint32 uiType, Uint32& uiHandleOUT)
{
FileStream* pFile = RESMAN->OpenFile(c_pszFilename);
if(!pFile)
{
DebugLog("Failed to load shader: %s", c_pszFilename);
return false;
}
Uint32 uiDataSize = pFile->GetFileSize();
if(uiDataSize == 0)
{
DebugLog("Shader '%s' appears empty!", c_pszFilename);
delete pFile;
return false;
}
// Load the data file to memory.
char* pszShaderSource = (char*)malloc(uiDataSize + 1); // + 1 for NULL terminate.
pFile->Read(pszShaderSource, uiDataSize, 1);
pFile->Close();
pszShaderSource[uiDataSize] = 0;
// Create and compile the shader object
uiHandleOUT = glCreateShader((GLenum)uiType);
glShaderSource(uiHandleOUT, 1, (const char**)&pszShaderSource, NULL);
DebugLog("------------ COMPILING: %s", c_pszFilename);
glCompileShader(uiHandleOUT);
// Test if compilation succeeded
GLint ShaderCompiled;
glGetShaderiv(uiHandleOUT, GL_COMPILE_STATUS, &ShaderCompiled);
if (!ShaderCompiled)
{
int i32InfoLogLength, i32CharsWritten;
glGetShaderiv(uiHandleOUT, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
char* pszInfoLog = new char[i32InfoLogLength];
glGetShaderInfoLog(uiHandleOUT, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
DebugLog("Failed to compile shader: %s", pszInfoLog);
delete [] pszInfoLog;
glDeleteShader(uiHandleOUT);
}
free(pszShaderSource);
delete pFile;
return ShaderCompiled;
}
示例7: OpenArchive
int BIFImporter::OpenArchive(const char* path)
{
if (stream) {
delete( stream );
stream = NULL;
}
char filename[_MAX_PATH];
ExtractFileFromPath(filename, path);
char cachePath[_MAX_PATH];
PathJoin(cachePath, core->CachePath, filename, NULL);
stream = FileStream::OpenFile(cachePath);
char Signature[8];
if (!stream) {
FileStream* file = FileStream::OpenFile(path);
if (!file) {
return GEM_ERROR;
}
if (file->Read(Signature, 8) == GEM_ERROR) {
delete file;
return GEM_ERROR;
}
if (strncmp(Signature, "BIF V1.0", 8) == 0) {
stream = DecompressBIF(file, cachePath);
delete file;
} else if (strncmp(Signature, "BIFCV1.0", 8) == 0) {
stream = DecompressBIFC(file, cachePath);
delete file;
} else if (strncmp( Signature, "BIFFV1 ", 8 ) == 0) {
file->Seek(0, GEM_STREAM_START);
stream = file;
} else {
delete file;
return GEM_ERROR;
}
}
if (!stream)
return GEM_ERROR;
stream->Read( Signature, 8 );
if (strncmp( Signature, "BIFFV1 ", 8 ) != 0) {
return GEM_ERROR;
}
ReadBIF();
return GEM_OK;
}
示例8: stream
vector<unsigned char>
File::ReadAllBytes (/*[in]*/ const PathName & path)
{
size_t size = GetSize(path);
vector<unsigned char> arr;
arr.resize (size);
FileStream stream (Open(path,
FileMode::Open,
FileAccess::Read,
false));
stream.Read (&arr[0], size);
return (arr);
}
示例9: CopyFile
void
PostScript::ExecuteEncapsulatedPostScript (/*[in]*/ const char * lpszFileName)
{
FileStream epsStream;
unsigned start = 0;
unsigned length = 0;
#if 0
// TODO
if (bmeps_can_handle(PathName(lpszFileName).GetBuffer()) != 0)
{
tracePS->WriteFormattedLine ("libdvi", T_("Converting %s to EPS..."), Q_(lpszFileName));
epsStream.Attach (ConvertToEPS(lpszFileName));
}
else
#endif
{
epsStream.Attach (File::Open(lpszFileName, FileMode::Open, FileAccess::Read, false));
struct
{
unsigned char magic[4];
unsigned char start[4];
unsigned char length[4];
} epsfheader;
if (epsStream.Read(&epsfheader, sizeof(epsfheader)) == sizeof(epsfheader)
&& epsfheader.magic[0] == 'E' + 0x80
&& epsfheader.magic[1] == 'P' + 0x80
&& epsfheader.magic[2] == 'S' + 0x80
&& epsfheader.magic[3] == 'F' + 0x80)
{
start = epsfheader.start[0];
start += epsfheader.start[1] * 256;
start += epsfheader.start[2] * 256 * 256;
start += epsfheader.start[3] * 256 * 256 * 256;
length = epsfheader.length[0];
length += epsfheader.length[1] * 256;
length += epsfheader.length[2] * 256 * 256;
length += epsfheader.length[3] * 256 * 256 * 256;
tracePS->WriteFormattedLine ("libdvi", T_("EPS has a binary header"));
tracePS->WriteFormattedLine ("libdvi", T_("start: %u"), static_cast<unsigned>(start));
tracePS->WriteFormattedLine ("libdvi", T_("length: %u"), static_cast<unsigned>(length));
}
}
epsStream.Seek (start, SeekOrigin::Begin);
CopyFile (epsStream, length);
}
示例10: while
void
PostScript::CopyFile (/*[in]*/ FileStream & stream,
/*[in]*/ unsigned length)
{
MIKTEX_ASSERT (IsOpen());
if (length == 0)
{
length = UINT_MAX;
}
size_t n;
char buf[4096];
while ((n = stream.Read(buf, min(4096, length))) > 0)
{
Write (buf, static_cast<unsigned>(n));
length -= static_cast<unsigned>(n);
}
}
示例11: LoadFile
// LoadFile
//------------------------------------------------------------------------------
bool ToolManifest::LoadFile( const AString & fileName, void * & content, uint32_t & contentSize ) const
{
// read the file into memory
FileStream fs;
if ( fs.Open( fileName.Get(), FileStream::READ_ONLY ) == false )
{
FLOG_ERROR( "Error opening file '%s' in Compiler ToolManifest\n", fileName.Get() );
return false;
}
contentSize = (uint32_t)fs.GetFileSize();
AutoPtr< void > mem( ALLOC( contentSize ) );
if ( fs.Read( mem.Get(), contentSize ) != contentSize )
{
FLOG_ERROR( "Error reading file '%s' in Compiler ToolManifest\n", fileName.Get() );
return false;
}
content = mem.Release();
return true;
}
示例12: TestMSVC_ShowIncludesWithWarnings
// TestMSVC_ShowIncludesWithWarnings
//------------------------------------------------------------------------------
void TestIncludeParser::TestMSVC_ShowIncludesWithWarnings() const
{
FBuild fb; // needed for CleanPath
FileStream f;
TEST_ASSERT( f.Open( "Data/TestIncludeParser/MSVC-ShowIncludes/WithWarnings.output", FileStream::READ_ONLY) )
const size_t fileSize = (size_t)f.GetFileSize();
AutoPtr< char > mem( (char *)ALLOC( fileSize + 1 ) );
TEST_ASSERT( f.Read( mem.Get(), fileSize ) == fileSize );
mem.Get()[ fileSize ] = 0;
CIncludeParser parser;
TEST_ASSERT( parser.ParseMSCL_Output( mem.Get(), fileSize ) );
// check number of includes found to prevent future regressions
const Array< AString > & includes = parser.GetIncludes();
TEST_ASSERT( includes.GetSize() == 0 );
#ifdef DEBUG
TEST_ASSERT( parser.GetNonUniqueCount() == 0 );
#endif
}
示例13: AddCacheFile
DataStream* ResourceManager::AddCacheFile(const char *filename)
{
if (!core->GameOnCD)
return FileStream::OpenFile(filename);
char fname[_MAX_PATH];
ExtractFileFromPath(fname, filename);
FileStream *dest = OpenCacheFile(fname);
// already in cache
if (dest)
return dest;
FileStream* src = FileStream::OpenFile(fname);
dest = CreateCacheFile(fname);
if (!src || !dest) {
printMessage("ResourceManager", "Failed to copy file '%s'\n", RED, fname);
abort();
}
size_t blockSize = 1024 * 1000;
char buff[1024 * 1000];
do {
if (blockSize > src->Remains())
blockSize = src->Remains();
size_t len = src->Read(buff, blockSize);
size_t c = dest->Write(buff, len);
if (c != len) {
printMessage("ResourceManager", "Failed to write to file '%s'\n", RED, fname);
abort();
}
} while (src->Remains());
delete src;
delete dest;
return OpenCacheFile(fname);
}
示例14: Test
void SuiteFileStream::Test()
{
const TUint kBytes = 256;
Bws<kBytes> b;
// Populate each position in the buffer with it's index.
for (TUint i=0; i<kBytes; i++) {
b.Append((TChar)i);
}
FileBrx f(b);
FileStream stream;
stream.SetFile(&f);
TEST(stream.Bytes() == kBytes);
// test basic reading
Bws<kBytes> buf;
stream.Read(buf);
TEST(buf == b);
TEST(stream.Tell() == kBytes);
// test that reads on a full buffer and at the end of a file throw
TEST_THROWS(stream.Read(buf), ReaderError);
buf.SetBytes(0);
TEST_THROWS(stream.Read(buf), ReaderError);
// test seeking
stream.Seek(0);
TEST(stream.Tell() == 0);
// test a stream can be (un)interrupted
stream.ReadInterrupt();
Bws<10> buf2;
TEST_THROWS(stream.Read(buf2), ReaderError);
stream.Interrupt(false);
stream.Read(buf2);
TEST(buf2.Bytes() == buf2.MaxBytes());
for (TUint i=0; i<10; i++) {
TEST(buf2[i] == b[i]);
}
// test that Read appends to a buffer
buf.SetBytes(0);
buf.Append(buf2);
stream.Read(buf);
TEST(buf.Bytes() == kBytes);
TEST(buf == b);
}
示例15: GetCacheFileName
// Retrieve
//------------------------------------------------------------------------------
/*virtual*/ bool Cache::Retrieve( const AString & cacheId, void * & data, size_t & dataSize )
{
data = nullptr;
dataSize = 0;
AStackString<> cacheFileName;
GetCacheFileName( cacheId, cacheFileName );
FileStream cacheFile;
if ( cacheFile.Open( cacheFileName.Get(), FileStream::READ_ONLY ) )
{
const size_t cacheFileSize = (size_t)cacheFile.GetFileSize();
AutoPtr< char > mem( (char *)ALLOC( cacheFileSize ) );
if ( cacheFile.Read( mem.Get(), cacheFileSize ) == cacheFileSize )
{
dataSize = cacheFileSize;
data = mem.Release();
return true;
}
}
return false;
}