1 #include "Bzip2Compressor.h"
4 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 Bzip2Compressor::Bzip2Compressor (
9 ::Compression::CompressorFactory_ptr compressor_factory
,
10 ::Compression::CompressionLevel compression_level
) :
11 BaseCompressor (compressor_factory
, compression_level
)
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 ()),
28 reinterpret_cast <char*>(const_cast<CORBA::Octet
*>(source
.get_buffer ())),
32 this->compression_level () * 25);
36 throw ::Compression::CompressionException (retval
, "");
40 target
.length (static_cast <CORBA::ULong
> (max_length
));
43 // Update statistics for this compressor
44 this->update_stats (source
.length (), target
.length ());
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 ()),
56 reinterpret_cast <char*>(const_cast<CORBA::Octet
*>(source
.get_buffer ())),
63 throw ::Compression::CompressionException (retval
, "");
67 target
.length (static_cast <CORBA::ULong
> (max_length
));
72 TAO_END_VERSIONED_NAMESPACE_DECL