7 #include "Alignment/Geners/interface/BZ2Handle.hh" 8 #include "Alignment/Geners/interface/CStringStream.hh" 9 #include "Alignment/Geners/interface/IOException.hh" 12 const unsigned long long len,
16 const unsigned long long bufLen,
22 strm.next_in =
reinterpret_cast<Bytef *
>(
const_cast<char *
>(
data));
25 strm.next_out =
reinterpret_cast<Bytef *
>(
buffer);
26 strm.avail_out = bufLen;
27 status = defl ? deflate(&strm, Z_FINISH) : inflate(&strm, Z_NO_FLUSH);
29 const unsigned have = bufLen - strm.avail_out;
32 throw gs::IOWriteFailure(
"In gs::doZlibCompression: sink stream failure");
33 }
while (strm.avail_out == 0);
36 assert(strm.avail_in == 0);
38 assert(deflateReset(&strm) == Z_OK);
40 assert(inflateReset(&strm) == Z_OK);
44 const unsigned long long len,
48 const unsigned long long bufLen,
54 strm.next_in =
const_cast<char *
>(
data);
58 strm.avail_out = bufLen;
59 status = defl ? BZ2_bzCompress(&strm, BZ_FINISH) : BZ2_bzDecompress(&strm);
61 const unsigned have = bufLen - strm.avail_out;
64 throw gs::IOWriteFailure(
"In gs::doBZ2Compression: sink stream failure");
65 }
while (
status != BZ_STREAM_END);
69 CStringStream::CStringStream(
const CompressionMode
m,
71 const unsigned minSizeToCompress,
72 const unsigned bufSize)
75 minSizeToCompress_(minSizeToCompress),
79 comprBuf_(bufSize > 1024
U ? bufSize : 1024
U),
84 void CStringStream::setCompressionMode(
const CompressionMode newmode) {
95 void CStringStream::readCompressed(std::istream &
in,
const unsigned compressionCode,
const unsigned long long len) {
101 if (len > readBuf_.size())
102 readBuf_.resize(len);
103 in.read(&readBuf_[0], len);
105 switch (static_cast<CompressionMode>(compressionCode)) {
107 this->
write(&readBuf_[0], len);
111 if (!inflator_.get())
112 inflator_ = std::make_unique<ZlibInflateHandle>();
113 doZlibCompression(&readBuf_[0], len,
false, inflator_->strm(), &comprBuf_[0], comprBuf_.size(), *
this);
120 BZ2InflateHandle
h(strm);
121 doBZ2Compression(&readBuf_[0], len,
false, strm, &comprBuf_[0], comprBuf_.size(), *
this);
125 assert(!
"Unhandled switch case in " 126 "CStringStream::readCompressed. " 127 "This is a bug. Please report.");
131 CStringStream::CompressionMode CStringStream::writeCompressed() {
135 unsigned long long len = 0;
136 const char *
data = buf_.getPutBuffer(&len);
138 return NOT_COMPRESSED;
140 if (mode_ == NOT_COMPRESSED || len < minSizeToCompress_) {
141 sink_->write(
data, len);
142 return NOT_COMPRESSED;
147 if (!deflator_.get())
148 deflator_ = std::make_unique<ZlibDeflateHandle>(compressionLevel_);
156 BZ2DeflateHandle
h(strm);
161 assert(!
"Unhandled switch case in " 162 "CStringStream::writeCompressed. " 163 "This is a bug. Please report.");
170 bool CStringStream::getCompressionModeByName(
const char *
name, CompressionMode *
m) {
171 static const char *
names[] = {
"n",
"z",
"b"};
174 for (
unsigned i = 0;
i <
sizeof(
names) /
sizeof(
names[0]); ++
i)
176 *
m =
static_cast<CompressionMode
>(
i);
182 std::string CStringStream::compressionModeName(
const CompressionMode
m,
const bool useShortName) {
186 mode = useShortName ?
"n" :
"not compressed";
189 mode = useShortName ?
"z" :
"zlib";
192 mode = useShortName ?
"b" :
"bzip2";
195 assert(!
"Unhandled switch case in " 196 "CStringStream::compressionModeName. " 197 "This is a bug. Please report.");
static void doBZ2Compression(const char *data, const unsigned long long len, const bool defl, bz_stream &strm, char *buffer, const unsigned long long bufLen, std::ostream &sink)
const std::string names[nVars_]
static void doZlibCompression(const char *data, const unsigned long long len, const bool defl, z_stream_s &strm, char *buffer, const unsigned long long bufLen, std::ostream &sink)
char data[epos_bytes_allocation]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
void reset(double vett[256])