Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:23

0001 #include "CondCore/CondDB/interface/FileUtils.h"
0002 #include "CondCore/CondDB/interface/Exception.h"
0003 #include <fstream>
0004 #include <sstream>
0005 
0006 bool cond::FileReader::read(const std::string& fileName) {
0007   std::ifstream inputFile;
0008   inputFile.open(fileName.c_str());
0009   if (!inputFile.good()) {
0010     std::stringstream msg;
0011     msg << "File \"" << fileName << "\" cannot be open.";
0012     inputFile.close();
0013     throw cond::Exception(msg.str());
0014   }
0015   // get pointer to associated buffer object
0016   std::filebuf* pbuf = inputFile.rdbuf();
0017   // get file size using buffer's members
0018   long size = pbuf->pubseekoff(0, std::ios::end, std::ios::in);
0019   pbuf->pubseekpos(0, std::ios::in);
0020   // allocate memory to contain file data
0021   char* buffer = new char[size + 1];
0022   // get file data
0023   pbuf->sgetn(buffer, size);
0024   inputFile.close();
0025   buffer[size] = 0;
0026   m_content += buffer;
0027   delete[] buffer;
0028   return true;
0029 }