10#include <boost/filesystem.hpp>
11#include <boost/filesystem/fstream.hpp>
12#include <boost/tokenizer.hpp>
13#include <boost/iostreams/device/file.hpp>
14#include <boost/iostreams/filtering_stream.hpp>
15#include <boost/iostreams/filter/gzip.hpp>
16#include <boost/iostreams/filter/bzip2.hpp>
29 : _iStreamPtr (iPORFileHelper._iStreamPtr) {
34 : _iStreamPtr (NULL) {
40 delete _iStreamPtr; _iStreamPtr = NULL;
45 assert (_iStreamPtr != NULL);
50 void PORFileHelper::init (
const PORFilePath_T& iPORFilePath) {
53 <<
"') exists, is readable and/or compressed.");
56 boost::filesystem::path lPORFilePath (iPORFilePath.begin(),
58 if (!(boost::filesystem::exists (lPORFilePath)
59 && boost::filesystem::is_regular_file (lPORFilePath))) {
61 <<
" does not exist or cannot be open." << std::endl);
64 +
" does not exist or cannot be read");
74 const boost::filesystem::path& lPORFileExtPath = lPORFilePath.extension();
75 const std::string& lPORFileExt = lPORFileExtPath.string();
76 if (lPORFileExt ==
".bz2") {
78 boost::iostreams::file_source cprdPORFile (iPORFilePath, std::ios_base::in
79 | std::ios_base::binary);
82 boost::iostreams::filtering_istream* bunzip2Filter_ptr =
83 new boost::iostreams::filtering_istream();
84 bunzip2Filter_ptr->push (boost::iostreams::bzip2_decompressor());
85 bunzip2Filter_ptr->push (cprdPORFile);
86 _iStreamPtr = bunzip2Filter_ptr;
88 }
else if (lPORFileExt ==
".gz") {
90 boost::iostreams::file_source cprdPORFile (iPORFilePath, std::ios_base::in
91 | std::ios_base::binary);
94 boost::iostreams::filtering_istream* gunzipFilter_ptr =
95 new boost::iostreams::filtering_istream();
96 gunzipFilter_ptr->push (boost::iostreams::gzip_decompressor());
97 gunzipFilter_ptr->push (cprdPORFile);
98 _iStreamPtr = gunzipFilter_ptr;
100 }
else if (lPORFileExt ==
".csv") {
102 _iStreamPtr =
new boost::filesystem::ifstream (iPORFilePath,
107 std::ostringstream errorStr;
108 errorStr <<
"The POR file " << iPORFilePath
109 <<
" has got an unknown extension ('" << lPORFileExt
110 <<
"'). Recognised extensions: .csv, .bz2, .gz";
112 throw FileExtensionUnknownException (errorStr.str());
#define OPENTREP_LOG_ERROR(iToBeLogged)
#define OPENTREP_LOG_DEBUG(iToBeLogged)
std::istream & getFileStreamRef() const
PORFileHelper(const PORFilePath_T &)