Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / Compression / bzip2 / Bzip2Compressor.cpp
blobf12f2ee42166ea95e8dadf8339c8c139b826c74f
1 #include "Bzip2Compressor.h"
2 #include "bzlib.h"
4 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
6 namespace TAO
8 Bzip2Compressor::Bzip2Compressor (
9 ::Compression::CompressorFactory_ptr compressor_factory,
10 ::Compression::CompressionLevel compression_level) :
11 BaseCompressor (compressor_factory, compression_level)
15 void
16 Bzip2Compressor::compress (
17 const ::Compression::Buffer & source,
18 ::Compression::Buffer & target
21 // Ensure maximum is at least a bit bigger than input length.
22 target.length (static_cast <CORBA::ULong> ((source.length () * 1.01) + 600));
24 unsigned int max_length = static_cast <unsigned int> ( target.maximum () );
26 int const retval = ::BZ2_bzBuffToBuffCompress (reinterpret_cast <char*>(target.get_buffer ()),
27 &max_length,
28 reinterpret_cast <char*>(const_cast<CORBA::Octet*>(source.get_buffer ())),
29 source.length (),
32 this->compression_level () * 25);
34 if (retval != BZ_OK)
36 throw ::Compression::CompressionException (retval, "");
38 else
40 target.length (static_cast <CORBA::ULong> (max_length));
43 // Update statistics for this compressor
44 this->update_stats (source.length (), target.length ());
47 void
48 Bzip2Compressor::decompress (
49 const ::Compression::Buffer & source,
50 ::Compression::Buffer & target)
52 unsigned int max_length = static_cast <unsigned int> (target.maximum ());
53 // todo, check 0,1 values
54 int const retval = ::BZ2_bzBuffToBuffDecompress (reinterpret_cast <char*>(target.get_buffer ()),
55 &max_length,
56 reinterpret_cast <char*>(const_cast<CORBA::Octet*>(source.get_buffer ())),
57 source.length (),
59 1);
61 if (retval != BZ_OK)
63 throw ::Compression::CompressionException (retval, "");
65 else
67 target.length (static_cast <CORBA::ULong> (max_length));
72 TAO_END_VERSIONED_NAMESPACE_DECL