GzipPostProcessing.cc
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* GzipPostProcessing.cc
*
* Created on: 25 sept. 2013
* Author: CS
*/
#include "GzipPostProcessing.hh"
#include "GzipNode.hh"
#include "PostProcessingRegistry.hh"
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem.hpp>
namespace postprocessing {
const std::string GzipPostProcessing::EXTENSION = ".gz";
/**
* Self-registering to post-processing factory
*/
std::string GzipPostProcessing::_key =
PostProcessingRegistry::getInstance().addElement(EXTENSION,
new GzipPostProcessing());
GzipPostProcessing::GzipPostProcessing() : PostProcessing() {
}
GzipPostProcessing::~GzipPostProcessing() {
}
/**
* Applies post-processing.
*/
void GzipPostProcessing::apply(PostProcessingAble* pOutput) {
_outputDestination = pOutput->getDestination();
for (auto file : pOutput->getOutputs()) {
_files.push_back(gzip(file, pOutput->getDestination()));
}
}
std::string GzipPostProcessing::gzip(std::string& pFile,
const std::string& pOutDir) {
std::string outFile = pFile + EXTENSION;
if (!pOutDir.empty()) {
boost::filesystem::path filePath(pFile);
outFile = pOutDir + "/" + filePath.filename().string() + EXTENSION;
}
std::ofstream file(outFile, std::ios_base::out | std::ios_base::binary);
std::ifstream in(pFile, std::ios_base::in);
boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
out.push(boost::iostreams::gzip_compressor());
out.push(file);
boost::iostreams::copy(in, out);
file.close();
boost::filesystem::path path(pFile);
boost::filesystem::remove(path);
return outFile;
}
/**
* Registers related node and process.
*/
void GzipPostProcessing::registerChildList(
std::map<std::string, boost::shared_ptr<AMDA::XMLConfigurator::NodeCfg>>& childList) {
childList["gzip"] = boost::shared_ptr<AMDA::XMLConfigurator::NodeCfg>(
new GzipNode());
}
} /* namespace postprocessing */