CMS 3D CMS Logo

Public Member Functions | Private Attributes

cond::FileReader Class Reference

#include <FileUtils.h>

List of all members.

Public Member Functions

const std::string & content () const
 FileReader ()
bool read (const std::string &fileName)
virtual ~FileReader ()

Private Attributes

std::string m_content

Detailed Description

Definition at line 7 of file FileUtils.h.


Constructor & Destructor Documentation

cond::FileReader::FileReader ( ) [inline]

Definition at line 27 of file FileUtils.h.

                          :m_content(""){
}
virtual cond::FileReader::~FileReader ( ) [inline, virtual]

Definition at line 13 of file FileUtils.h.

{}

Member Function Documentation

const std::string & cond::FileReader::content ( ) const [inline]
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, recoMuon::in, analyzePatCleaning_cfg::inputFile, m_content, runTheMatrix::msg, and findQualityFiles::size.

Referenced by cond::XMLAuthenticationService::XMLAuthenticationService::processFile(), and cond::DecodingKey::readFromFile().

                                                  {
  std::ifstream inputFile;
  inputFile.open (fileName.c_str());
  if(!inputFile.good()){
    std::stringstream msg;
    msg << "File \"" << fileName << "\" cannot be open.";
    inputFile.close();
    throw cond::Exception(msg.str());
  }
  // get pointer to associated buffer object
  std::filebuf* pbuf=inputFile.rdbuf();
  // get file size using buffer's members
  long size=pbuf->pubseekoff (0,std::ios::end,std::ios::in);
  pbuf->pubseekpos (0,std::ios::in);
  // allocate memory to contain file data
  char* buffer=new char[size+1];
  // get file data  
  pbuf->sgetn (buffer,size);
  inputFile.close();
  buffer[size]=0;
  m_content += buffer;
  delete [] buffer;
  return true;
}

Member Data Documentation

std::string cond::FileReader::m_content [private]

Definition at line 21 of file FileUtils.h.

Referenced by read().