CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CondCore/DBCommon/src/FileUtils.cc

Go to the documentation of this file.
00001 #include "CondCore/DBCommon/interface/FileUtils.h"
00002 #include "CondCore/DBCommon/interface/Exception.h"
00003 #include <fstream>
00004 #include <sstream>
00005 
00006 bool cond::FileReader::read(const std::string& fileName){
00031   std::ifstream inputFile;
00032   inputFile.open (fileName.c_str());
00033   if(!inputFile.good()){
00034     std::stringstream msg;
00035     msg << "File \"" << fileName << "\" cannot be open.";
00036     inputFile.close();
00037     throw cond::Exception(msg.str());
00038   }
00039   // get pointer to associated buffer object
00040   std::filebuf* pbuf=inputFile.rdbuf();
00041   // get file size using buffer's members
00042   long size=pbuf->pubseekoff (0,std::ios::end,std::ios::in);
00043   pbuf->pubseekpos (0,std::ios::in);
00044   // allocate memory to contain file data
00045   char* buffer=new char[size+1];
00046   // get file data  
00047   pbuf->sgetn (buffer,size);
00048   inputFile.close();
00049   buffer[size]=0;
00050   m_content += buffer;
00051   delete [] buffer;
00052   return true;
00053 }