#include <CondCore/DBCommon/interface/FileUtils.h>
Public Member Functions | |
const std::string & | content () const |
FileReader () | |
bool | read (const std::string &fileName) |
virtual | ~FileReader () |
Private Attributes | |
std::string | m_content |
Definition at line 7 of file FileUtils.h.
cond::FileReader::FileReader | ( | ) | [inline] |
virtual cond::FileReader::~FileReader | ( | ) | [inline, virtual] |
const std::string & cond::FileReader::content | ( | ) | const [inline] |
Definition at line 31 of file FileUtils.h.
References m_content.
Referenced by cond::XMLAuthenticationService::XMLAuthenticationService::processFile(), and cond::DecodingKey::readFromFile().
00031 { 00032 return m_content; 00033 }
bool cond::FileReader::read | ( | const std::string & | fileName | ) |
struct stat st; if (stat(inputFileName.c_str(), &st) < 0){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "\" not found." << seal::flush; return false; }
std::vector<char> buf(st.st_size, 0); int fd = open(inputFileName.c_str(), O_RDONLY); if (fd < 0){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "\" cannot be open." << seal::flush; close(fd); return false; }
if (read(fd, &buf[0], st.st_size) != st.st_size){ seal::MessageStream log( this, this->name(),seal::Msg::Verbose ); log << seal::Msg::Error << "File \"" << inputFileName << "\" cannot be open for reading." << seal::flush; close(fd); return false; } std::string content(&buf[0], &buf[0]+st.st_size);
Definition at line 6 of file FileUtils.cc.
References end, Exception, in, outputToXml::inputFile, m_content, alivecheck_mergeAndRegister::msg, and size.
Referenced by cond::XMLAuthenticationService::XMLAuthenticationService::processFile(), and cond::DecodingKey::readFromFile().
00006 { 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 }
std::string cond::FileReader::m_content [private] |