TBool CTestStep_MMF_SWCDWRAP_U_0200::CompareL(RFile& aFile1, RFile& aFile2, TUint aCompareLength) { TBool compareResult = ETrue; //ETrue if both files are identical HBufC8* file1Buffer = HBufC8::NewLC(4); HBufC8* file2Buffer = HBufC8::NewLC(4); //can't use HBufC8 directly with file server as //HBufC8 is derived from TDesC8 but file server expects TDes8 TPtr8 file1Ptr(file1Buffer->Des()); TPtr8 file2Ptr(file2Buffer->Des()); //cannot compare file all in one go as we might run //out of heap - so compare in 4 byte chunks for (TUint pos=0;pos<aCompareLength;pos+=4) { aFile1.Read(static_cast<TInt>(pos), file1Ptr, 4); aFile2.Read(static_cast<TInt>(pos), file2Ptr, 4); if (file1Buffer->Compare(*file2Buffer) != 0) { compareResult = EFalse; //file mismatch } } CleanupStack::PopAndDestroy( 2 ); //file1Buffer & file2Buffer return compareResult; }
TInt CTmsTestStep::ReadNextLineL( RFile &aFile, TDes8 &aLine ) // read a cr/lf limiited line from the file, assumes file is a valid file // and that aLine is of sufficient length to hold the data { aLine.Zero(); TBuf8<1> chr; for (;;) { aFile.Read(chr); if ( chr.Length() == 0 ) { break; } if (chr.CompareF(KRet) == 0) { // got a line, exctract newline as well aFile.Read(chr); break; } else { aLine.Append(chr); } } return aLine.Length(); }
/** CompareAttachmentFiles Compares the file associated with the attachments. @internalTechnology @pre None @post None */ TBool CMtfTestActionCompareEmails::CompareAttachmentFilesL(RFile aFile1, RFile aFile2) { //Do the byte by byte comparison TBool ret = ETrue; TInt sz1, sz2; User::LeaveIfError( aFile1.Size(sz1) ); User::LeaveIfError( aFile2.Size(sz2) ); if( sz1 != sz2 ) { TestCase().INFO_PRINTF3( _L("File size mismatch 1(%d) 2(%d)"), sz1, sz2 ); ret = EFalse; } else { TBuf8<1> char1; TBuf8<1> char2; TInt len1, len2; do { aFile1.Read(char1); aFile2.Read(char2); len1 = char1.Length(); len2 = char2.Length(); if( char1.Compare( char2 ) != 0 ) { ret = EFalse; break; } } while( len1 && len2 ); } return ret; }
/** Read the zip header from the specified zip file into the TEZGZipHeader object @param aFile the zip file to read from @param aHeader the target header object @leave KEZlibErrBadGZipHeader invalid zip header @leave ... Any of the system wide error codes */ EXPORT_C void EZGZipFile::ReadHeaderL(RFile &aFile, TEZGZipHeader &aHeader) { TInt obligatoryData = sizeof(aHeader.iId1) + sizeof(aHeader.iId2) + sizeof(aHeader.iCompressionMethod) + sizeof(aHeader.iFlags) + sizeof(aHeader.iTime) + sizeof(aHeader.iExtraFlags) + sizeof(aHeader.iOs); TPtr8 des(&aHeader.iId1,0,obligatoryData); TInt err = aFile.Read(des); if (err != KErrNone || (des.Size() != obligatoryData)) User::Leave(KEZlibErrBadGZipHeader); if (aHeader.iId1 != ID1 || aHeader.iId2 != ID2) User::Leave(KEZlibErrBadGZipHeader); if (aHeader.iFlags & (1 << EFExtra)) // then the extra bit is set { des.Set(REINTERPRET_CAST(TUint8 *,&aHeader.iXlen),0,sizeof(aHeader.iXlen)); err = aFile.Read(des); if (err != KErrNone || des.Size() != sizeof(aHeader.iXlen) || aHeader.iXlen < 0) User::Leave(KEZlibErrBadGZipHeader); aHeader.iExtra = HBufC8::NewMaxL(aHeader.iXlen); TPtr8 des = aHeader.iExtra->Des(); err = aFile.Read(des); if (err != KErrNone || des.Size() != aHeader.iXlen) User::Leave(KEZlibErrBadGZipHeader); }
void CRecognizeStep::ReadSymbianHeaderL(RFile& aFile, TUid& aUid1, TUid& aUid2, TUid& aUid3) { TInt uidLen = sizeof(TInt32); TPckg<TInt32> uid1(aUid1.iUid); User::LeaveIfError(aFile.Read(uid1, uidLen)); if (uid1.Length() != uidLen) { User::Leave(KErrUnderflow); } TPckg<TInt32> uid2(aUid2.iUid); User::LeaveIfError(aFile.Read(uid2, uidLen)); if (uid1.Length() != uidLen) { User::Leave(KErrUnderflow); } TPckg<TInt32> uid3(aUid3.iUid); User::LeaveIfError(aFile.Read(uid3, uidLen)); if (uid1.Length() != uidLen) { User::Leave(KErrUnderflow); } }
void TPLauncherConfig::Load() { RFile file; if(!file.Open(CEikonEnv::Static()->FsSession(), iIniFileName, 0)) { TInt version; TPckg<TInt> pkg_version(version); TPckg<TBool> pkg_Pad(iPad); TBuf8<KMaxFileName> pad0; // reserved for future use (6 words) TPtr8 picoCfg((TUint8*) &iEmuConfig, sizeof(iEmuConfig)); file.Read(pkg_version); file.Read(pkg_Pad); file.Read(pad0, 24); file.Read(pad0, KMaxFileName); file.Read(picoCfg); TBuf8<KMaxFileName> file8(pad0.Ptr()); // take as zero terminated string iLastROMFile.Copy(file8); //DEBUGPRINT(_L("[app] iLastROMFile (%i): %S"), iLastROMFile.Length(), &iLastROMFile); file.Close(); } }
void CWmDrmDataStore::ReadInitialFreeSpaceL( const TDesC& aFileName, TBool& aConfiguredDrive ) { RFile file; TBuf8<KMaxTInt64BufLength + 2 * KAESKeyLength> encryptedData; TBuf8<KMaxTInt64BufLength + 2 * KAESKeyLength> decryptedData; TBuf8<KAESKeyLength> key; TBuf8<KAESKeyLength> iv; CBufferedDecryptor* decryptor = NULL; CModeCBCDecryptor* cbcDecryptor = NULL; CAESDecryptor* aesDecryptor = NULL; CPaddingPKCS7* padding = NULL; TInt size = 0; LOGFN( "CWmDrmDataStore::ReadInitialFreeSpaceL" ); User::LeaveIfError( file.Open( iServer->Fs(), aFileName, EFileRead ) ); CleanupClosePushL( file ); User::LeaveIfError( file.Size( size ) ); if( size != ( 2 * KAESKeyLength ) ) { User::Leave(KErrCorrupt); } User::LeaveIfError( file.Read( iv ) ); User::LeaveIfError( file.Read( encryptedData ) ); #if defined(FF_PLATFORM_SIMULATOR) || defined(__WINSCW__) key.Copy( KDummyKey ); #else iServer->Cache()->iKeyStorage->GetDeviceSpecificKeyL( key ); #endif aesDecryptor = CAESDecryptor::NewL( key ); CleanupStack::PushL( aesDecryptor ); cbcDecryptor = CModeCBCDecryptor::NewL( aesDecryptor, iv ); CleanupStack::Pop( aesDecryptor ); CleanupStack::PushL( cbcDecryptor ); padding = CPaddingPKCS7::NewL( KAESKeyLength ); CleanupStack::PushL( padding ); decryptor = CBufferedDecryptor::NewL( cbcDecryptor, padding ); CleanupStack::Pop( 2, cbcDecryptor ); //padding, cbcDecryptor CleanupStack::PushL( decryptor ); decryptor->ProcessFinalL( encryptedData, decryptedData ); CleanupStack::PopAndDestroy( 2, &file ); //decryptor, file TLex8 lex( decryptedData ); if ( aConfiguredDrive ) { User::LeaveIfError( lex.Val( iInitialFreeSpace2 ) ); } else { User::LeaveIfError( lex.Val( iInitialFreeSpace ) ); } }
/** @SYMTestCaseID SYSLIB-XML-CT-3736 @SYMTestCaseDesc Parsing an xml file with extended character.. @SYMTestPriority Medium @SYMTestActions Checks that the parser can deal with extended characters - locales outside of ascii. Parses doc_jp_utf.xml, reconstitutes it as xml, and compares with ref_doc_jp_utf.xml. @SYMTestExpectedResults The reconstructed document is the same as the original document. @SYMDEF DEF051379 */ LOCAL_C void DEF051379L() { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); TInt pos = 0; //open a temporary results file RFile result; TFileName filename; User::LeaveIfError(result.Temp(fs, _L("C:\\"), filename, EFileWrite)); CleanupClosePushL(result); //reconstitutes the xml from parser callbacks TRebuildingContentHandler contentHandler(result); CParser* parser = CParser::NewLC(KParserDataType, contentHandler); //parse the file ParseL(*parser, fs, KEncodingTestFile()); test(contentHandler.iError==KErrNone); //open the reference file, and compare with results file RFile ref; User::LeaveIfError(ref.Open(fs, KEncodingRefFile, EFileRead)); CleanupClosePushL(ref); User::LeaveIfError(result.Seek(ESeekStart,pos)); TInt resultSize; User::LeaveIfError(result.Size(resultSize)); TInt refSize; User::LeaveIfError(ref.Size(refSize)); test(resultSize==refSize); TBuf8<256> refBuf; TBuf8<256> resultBuf; while(ref.Read(refBuf)==KErrNone && result.Read(resultBuf)==KErrNone && refBuf.Length()>0) test(refBuf==resultBuf); //check that RFile::Read has read the entire contents of each file, //so that length (from cursor position to end of file) == 0 test(refBuf.Length()==0 && resultBuf.Length()==0); CleanupStack::PopAndDestroy(&ref); CleanupStack::PopAndDestroy(parser); CleanupStack::PopAndDestroy(&result); fs.Delete(filename); CleanupStack::PopAndDestroy(&fs); }
LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2) // // Seek to aCluster and check it is found correctly // { TBuf8<508> seekBuf(508); TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf); test_KErrNone(r); test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1); r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf); test_KErrNone(r); test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2); }
void Read(RFile &file){ { TPtr8 ptr((byte*)&signature, 4); file.Read(ptr); } { TPtr8 ptr((byte*)&_version_needed, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&_flags, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&compression, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&_lastModTime, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&_lastModDate, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&_crc, 4); file.Read(ptr); } { TPtr8 ptr((byte*)&_sz_compressed, 4); file.Read(ptr); } { TPtr8 ptr((byte*)&_sz_uncompressed, 4); file.Read(ptr); } { TPtr8 ptr((byte*)&filenameLen, 2); file.Read(ptr); } { TPtr8 ptr((byte*)&extraFieldLen, 2); file.Read(ptr); } }
// Bitwise comparison of iOriginalFile and iNewFile TInt CCompare::CompareFilesL() { TInt res = KErrNone; RFs theFs; CleanupClosePushL(theFs); User::LeaveIfError(theFs.Connect()); RFile original; TInt r = original.Open(theFs, iOriginalFile, EFileRead); User::LeaveIfError(r); CleanupClosePushL(original); RFile generated; r = generated.Open(theFs, iNewFile, EFileRead); User::LeaveIfError(r); CleanupClosePushL(generated); TInt pos1 = 0; TInt pos2 = 0; TBuf8<1> ptr1; TBuf8<1> ptr2; original.Read(pos1, ptr1); generated.Read(pos2, ptr2); while (ptr1.Length()!=0) { if (ptr1.Compare(ptr2) != 0) { res = KErrDifferent; pos = pos1; break; } pos1++; pos2++; original.Read(pos1, ptr1); generated.Read(pos2, ptr2); } if ((res != KErrDifferent)&& (ptr2.Length()!=0)) { res = KErrDifferent; pos = pos1; } CleanupStack::PopAndDestroy(3, &theFs); return res; }
TInt CUptULogger::GetDataL(TUint8*& aData, TUint& aSize) { RFs fsSession; CleanupClosePushL(fsSession); User::LeaveIfError(fsSession.Connect()); RFile file; TInt error = file.Open(fsSession, KTextvalue, EFileRead); if(error == KErrNone) { TInt size = 0; file.Size(size); aSize = size; aData = new TUint8[aSize]; if(!aData) error = KErrNoMemory; if(!error) { TPtr8 ptr(aData, aSize); error = file.Read(ptr); } file.Close();//is really called at fsSession.Close(); fsSession.Close(); } CleanupStack::PopAndDestroy();//fsSession return error; }
HBufC8* CTestConfig::ReadFileL(const TDesC& aFile) const { //Returns a HBufC8 with the contents of aFile RFile file; const TInt err = file.Open(iFs, aFile, EFileShareAny | EFileRead); if (err != KErrNone) { TParse fileOut; User::LeaveIfError(ResolveFile(iFs, *iComponent, aFile, fileOut)); User::LeaveIfError(file.Open(iFs, fileOut.FullName(), EFileShareAny | EFileRead)); } CleanupClosePushL(file); TInt size = 0; User::LeaveIfError(file.Size(size)); HBufC8* contents = HBufC8::NewLC(size + 4); TPtr8 contentsPtr(contents->Des()); User::LeaveIfError(file.Read(0, contentsPtr)); CleanupStack::Pop(contents); CleanupStack::PopAndDestroy(&file); return contents; }
HBufC8* CTPKCS7StepBase::readFileL (TPtrC tag) { TPtrC fileName; if (GetStringFromConfig(ConfigSection(), tag, fileName) == EFalse) { return NULL; } RFile file; if (file.Open(iFs, fileName, EFileRead) != KErrNone) { INFO_PRINTF2(_L("Cannot open file %S for reading"), &fileName); return NULL; } CleanupClosePushL(file); TInt fileSize = 0; User::LeaveIfError(file.Size(fileSize)); HBufC8* result = HBufC8::NewL(fileSize); result->Des().SetLength(fileSize); TPtr8 rawDataPtr(result->Des()); rawDataPtr.SetLength(fileSize); file.Read (rawDataPtr); CleanupStack::PopAndDestroy (&file); INFO_PRINTF3(_L("Read %d octets from %S"), result->Size(), &fileName); return result; }
// From MMDXMLParserDataProvided // TODO: Should GetData be a leaving function? Allows more flexibility to implementations of this funtion? void CTestDataSupplier::GetData(TPtrC8 &aPtr, TRequestStatus &aStatus) { // Read the data into the descriptor delete iCurrentChunk; iCurrentChunk = NULL; iCurrentChunk = HBufC8::NewL(iChunkSize); TPtr8 chunk = iCurrentChunk->Des(); iFile.Read(chunk, iChunkSize); // Ignore the error code, assume end of file if we haven't read any data. TDataProviderResults result; if (iCurrentChunk->Length() != 0) { aPtr.Set(*iCurrentChunk); result = KMoreData; } else { // Assume that if we haven't got any data then we're at the end of the stream. result = KDataStreamEnd; } // iChunkSize++; TRequestStatus *s = &aStatus; User::RequestComplete(s, (TInt)result); return; }
void TFileReader::Next(TUint8& aVal,TInt& aLength) // // Read aLength contiguous bytes with aVal // { if (iPos==iData.Length()) { TInt r=iFile.Read(iData); test_KErrNone(r); iPos=0; if (iData.Length()==0) { aLength=0; return; } } aVal=iData[iPos]; aLength=0; while(iPos<iData.Length()) { if (iData[iPos]!=aVal) break; iPos++; aLength++; } }
TInt CFloggerTest028_Sync_Static_HexDump::DoTestCheckWriteL() { RFile logFile; HBufC8* hBuffer; TInt listfilesize,returnCode; RFs fileSystem; //For file operation create a file system User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(logFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(logFile); User::LeaveIfError(logFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); ; //To access the buffer // Read from position 0: start of file User::LeaveIfError(returnCode = logFile.Read(ptrString)); returnCode = ptrString.Find(KTestMessageAsHex8); //find the test descriptor in the buffer read //from the file CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); //logFile if (returnCode > 0) return KErrNone; else return KErrNotFound; }
/** ConstructL() Reads the machine name from the Machine config file("c:\\msgtest\\MachineName.txt") and constructs the data members. @param aPtrEmailAdd */ EXPORT_C void CT_MsgUtilsConfigFileMachineName::ConstructL(const TDesC& aPtrEmailAdd) { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); RFile file; User::LeaveIfError(file.Open(fs, KFileName, EFileRead)); CleanupClosePushL(file); TInt fileSize; User::LeaveIfError(file.Size(fileSize)); iMachineName = HBufC8::NewL(fileSize); TPtr8 bufferPtr = iMachineName->Des(); User::LeaveIfError(file.Read(bufferPtr)); if (aPtrEmailAdd.Compare(_L("NONE"))==0) iMachineNameEmail = HBufC::NewL(iMachineName->Length() + KAtEmailAddress.iTypeLength); else iMachineNameEmail = HBufC::NewL(iMachineName->Length() + aPtrEmailAdd.Length() + 1); iMachineNameEmail->Des().Copy(*iMachineName); if (aPtrEmailAdd.Compare(_L("NONE"))==0) iMachineNameEmail->Des().Append(KAtEmailAddress); else { iMachineNameEmail->Des().Append(_L("@")); iMachineNameEmail->Des().Append(aPtrEmailAdd); } CleanupStack::PopAndDestroy(2,&fs); }
/** * Reads the whole content of the Jad file and returns it in * buffer in Symbian Unicode character set. * @param[in] aJarFile * @return pointer to HBufC that contains the Jad file, * ownership is transferred to caller * @exception If jad file content cannot be read */ HBufC *CSilentMIDletInstall::GetJadContentL(const TDesC& aJadFileName) { JELOG2(EJavaPreinstaller); TInt err; RFile jadFile; err = jadFile.Open(iFs, aJadFileName, EFileRead); User::LeaveIfError(err); CleanupClosePushL(jadFile); // Reserve buffer for Jad in UTF-8 char set TInt jadSize = 0; err = jadFile.Size(jadSize); User::LeaveIfError(err); HBufC8 *bufUtf8Jad = HBufC8::NewL(jadSize); CleanupStack::PushL(bufUtf8Jad); // Read the content in Utf8 char set TPtr8 tmpPtr(bufUtf8Jad->Des()); err = jadFile.Read(tmpPtr, jadSize); User::LeaveIfError(err); // Convert to Unicode HBufC *bufUnicodeJad = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*bufUtf8Jad); CleanupStack::PopAndDestroy(bufUtf8Jad); CleanupStack::PopAndDestroy(&jadFile); // Return to caller return bufUnicodeJad; } // GetJadContentL
/** * Hash file in pieces * * @param aFileName File name to be hashed * @param aDes Hash value * * @return N/A * * @leave System wide error */ void CT_DataVerify::HashFileL( const TFileName& aFileName, TDes8& aDes ) { RFile file; User::LeaveIfError( file.Open( iFs, aFileName, EFileRead ) ); CleanupClosePushL( file ); TBuf8<DataVerify::KBufsize> buf; TInt error = KErrNone; iMD5->Reset(); // File can be hashed in pieces while( error == KErrNone ) // loop until something goes wrong { error = file.Read( buf, DataVerify::KBufsize ); if( buf.Length() != 0 ) { // MD5 checksum is calculated in pieces iMD5->Update(buf); } else { // file ended, end loop break; } } // Return calculated MD5 checksum aDes = iMD5->Final(); CleanupStack::PopAndDestroy(&file); // file.Close }
/** Read a file asynchronously in blocks of aBlockSize size @param fs RFs object @param aFileRead RFile object, needs to exist beyond the scope of this function @param aFile File name @param aSize Size of the file in bytes @param aBlockSize Size of the blocks to be used in bytes @param aStatus TRequestStatus array for all the requests @return KErrNone */ TInt ReadFileAsync(RFs& fs, RFile& aFileRead, TDes16& aFile, TInt aBlockSize, TRequestStatus aStatus[]) { TInt r = 0, size = 0; TEST(aBlockSize > 0); // Block size must be greater than 0 r = aFileRead.Open(fs, aFile, EFileShareAny|EFileRead|EFileReadDirectIO); TESTERROR(r); r = aFileRead.Size(size); TESTERROR(r); TInt j = 0, i = 0; while(j < size) { aFileRead.Read(gBufReadPtr, aBlockSize, aStatus[i]); test (aStatus[i].Int() == KErrNone || aStatus[i].Int() == KRequestPending); i++; TESTERROR(r); j += aBlockSize; } return KErrNone; }
void CPolicyNormalizer::ReadFileL( TFileName aPath ) { RFs fss; User::LeaveIfError(fss.Connect()); CleanupClosePushL(fss); if(iPath) { delete iPath; iPath = NULL; } iPath = aPath.AllocL(); TFileName iFileName(aPath); RFile xmlFile; TInt err = xmlFile.Open(fss , iFileName, EFileRead ); if(err == KErrNone) { TInt size; xmlFile.Size(size); HBufC8 *iBuf=HBufC8::NewL(size); TPtr8 buf8ptr(iBuf->Des()); xmlFile.Read(buf8ptr,size); xmlFile.Close(); TInt leaveCode(KErrNone); TRAP leaveCode, ParseL(buf8ptr) ); leaveCode = 0; // not used currently delete iBuf; iBuf = NULL; }
TInt CPlayAudioFile::ReadTestFileInBuffer() { RFs fs; TInt err = fs.Connect(); if(err != KErrNone) { return err; } RFile file; err = file.Open(fs,_L("c:\\mm\\mmf\\testfiles\\mdf\\depeche1.wav"), EFileRead); if (err == KErrNone) { TInt size; err = file.Size(size); if (err == KErrNone) { iSourceFile = HBufC8::NewMax(size); if(!iSourceFile) { return KErrNoMemory; } TPtr8 ptr = iSourceFile->Des(); file.Read(ptr,size); file.Close(); } fs.Close(); } return err; }
// Tests the contents of a file void CTestContactsPBAPExportContents::TestContentsL() { // Tests that when a leave occurs, the exported file doesn't contain any data RFs fsSession; TInt returnVal; RFile file; TBuf8<20> buf; User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); TFindFile findFile(fsSession); fsSession.SetSessionPath(KPath); returnVal = findFile.FindByDir(KExportLeaveFile, KPath); if(returnVal == KErrNone) { User::LeaveIfError(file.Open(fsSession, KExportLeaveFile, EFileWrite)); file.Read(buf); // test that the exported file has no content if(buf.Length() == 0) { SetTestStepResult(EPass); } else { SetTestStepResult(EFail); } } else { SetTestStepResult(EFail); } file.Close(); CleanupStack::PopAndDestroy(&fsSession); }
void CUPnPRootDeviceInfoContainer::ConstructL ( ) { iRootDeviceDescription = CUPnPDeviceDescription::NewL ( ); RFile fileHandle; RFs fs; User::LeaveIfError ( fs.Connect ( ) ); CleanupClosePushL ( fs ); TInt err = fileHandle.Open ( fs, _L("z:\\private\\101F7989\\upnp\\device.xml"), EFileShareReadersOnly ); // ..remove Hard coded User::LeaveIfError ( err ); CleanupClosePushL ( fileHandle ); iStringPoolMgr = CStringPoolManager::NewL ( ); const RStringPool& stringPool = iStringPoolMgr->StringPool(); CUPnPDescriptionParser* parser = CUPnPDescriptionParser::NewL (stringPool, CUPnPDescriptionParser::EDevice); CleanupStack::PushL ( parser ); TInt fileSize = 0; fileHandle.Size ( fileSize ); HBufC8* buf = HBufC8::NewLC ( fileSize ); TPtr8 ptr = buf->Des( ); User::LeaveIfError ( fileHandle.Read ( ptr, fileSize ) ); iRootDeviceDescription = static_cast<CUPnPDeviceDescription*> (parser->ParseDescriptionBufL( ptr )); CleanupStack::PopAndDestroy ( buf ); CleanupStack::PopAndDestroy ( parser ); CleanupStack::PopAndDestroy ( &fileHandle ); CleanupStack::PopAndDestroy ( &fs ); }
void CCommandInfoFile::ReadFileL(RFs& aFs, const TDesC& aFileName) { // Read the file into a buffer. RFile file; StaticLeaveIfErr(file.Open(aFs, aFileName, EFileRead | EFileShareReadersOnly), _L("Couldn't open '%S' for reading"), &aFileName); CleanupClosePushL(file); TInt fileSize; User::LeaveIfError(file.Size(fileSize)); RBuf8 buf8; buf8.CreateL(fileSize); buf8.CleanupClosePushL(); User::LeaveIfError(file.Read(buf8)); RBuf& buf = NewBuffer(); buf.CreateL(fileSize); buf.Copy(buf8); CleanupStack::PopAndDestroy(2, &file); TLex lex(buf); while (!lex.Eos()) { if (iProcessInclude || !iCurrentChild) { ReadDetailsL(lex, aFs, aFileName); } else { iCurrentChild->ReadDetailsL(lex, aFs, aFileName); } } }
void CMyXmlEle::ReadFileL(TFileName aPath) { RFs fss; User::LeaveIfError(fss.Connect()); CleanupClosePushL(fss); TFileName iFileName1(aPath); RFile xmlFile; xmlFile.Open(fss , iFileName1, EFileRead ); TInt size; xmlFile.Size(size); HBufC8 *iBuf=HBufC8::NewL(size); TPtr8 buf8ptr(iBuf->Des()); xmlFile.Read(buf8ptr,size); xmlFile.Close(); size = iBuf->Length(); if(size > 0) { TPtr8 buf8ptr(iBuf->Des()); TRAPD (err, ParseL(buf8ptr)); } delete iBuf; CleanupStack::PopAndDestroy(1); // fss }
TVerdict CTestVclntVideoDes::DoTestStepPreambleL() { TPtrC filename; if(!GetStringFromConfig(iSectName, iKeyName, filename)) return EInconclusive; RFs fs; RFile file; TInt size = 0; // connect to file system and open file User::LeaveIfError(fs.Connect()); User::LeaveIfError(file.Open(fs,filename,EFileRead)); CleanupClosePushL(file); // Set HBuf size User::LeaveIfError(file.Size(size)); INFO_PRINTF2(_L("size of file = %d\n"),size);//Statement Changed under DEF105143 iVideo = HBufC8::NewMaxL(size); // read data into Hbuf TPtr8 bufferDes(iVideo->Des()); User::LeaveIfError(file.Read(bufferDes)); CleanupStack::PopAndDestroy(); //file return CTestMmfVclntStep::DoTestStepPreambleL(); }
EXPORT_C HBufC8* CTestUtils::ReadFileLC(const TDesC& aFile) { //Returns a HBufC8 with the contents of aFile RFile file; User::LeaveIfError(file.Open(iFs, aFile, EFileShareAny | EFileRead)); CleanupClosePushL(file); TInt size = 0; TInt err = file.Size(size); if (err) { Printf(_L("ReadFileLC(%S) leaving with %d. Unable to size file\n"), &aFile, err); User::Leave(err); } HBufC8* contents = HBufC8::NewLC(size + 4); TPtr8 contentsPtr(contents->Des()); err = file.Read(0, contentsPtr); if (err) { Printf(_L("ReadFileLC(%S) leaving with %d. Unable to read file\n"), &aFile, err); User::Leave(err); } CleanupStack::Pop(); //contents CleanupStack::PopAndDestroy(); //file CleanupStack::PushL(contents); return contents; }
TInt CFloggerTest025_BuildTestUdeb1::DoTestCheckWriteL() { RFile theFile; HBufC8 * hBuffer; TInt listfilesize; TInt returnCode; RFs fileSystem; //For file operation create a file system User::After(KTimeToLog); User::LeaveIfError(fileSystem.Connect()); //Open the file in the read mode User::LeaveIfError(theFile.Open(fileSystem,KFloggerOutputFile,EFileRead)); CleanupClosePushL(theFile); User::LeaveIfError(returnCode = theFile.Size(listfilesize)); //Size of the file hBuffer = HBufC8::New(listfilesize); //Allocate the buffer CleanupStack::PushL(hBuffer); TPtr8 ptrString = hBuffer->Des(); ; //To hold the buffer // Read from position 0: start of file returnCode = theFile.Read(ptrString); if (returnCode == KErrNone) returnCode = ptrString.Find(KTestMessage8); //find the test descriptor in the buffer read //from the file CleanupStack::PopAndDestroy(hBuffer); CleanupStack::PopAndDestroy(); // For theFile object if (returnCode > 0) return KErrNone; else return KErrGeneral; }