Go to the documentation of this file.00001 #include "Bzip2Compressor.h"
00002
00003 ACE_RCSID (BZIP2,
00004 Bzip2Compressor,
00005 "$Id: Bzip2Compressor.cpp 84843 2009-03-16 16:38:54Z msmit $")
00006
00007 #include "bzlib.h"
00008
00009 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 namespace TAO
00012 {
00013 Bzip2Compressor::Bzip2Compressor (
00014 ::Compression::CompressionLevel compression_level,
00015 ::Compression::CompressorFactory_ptr compressor_factory) :
00016 BaseCompressor (compression_level, compressor_factory)
00017 {
00018 }
00019
00020 void
00021 Bzip2Compressor::compress (
00022 const ::Compression::Buffer & source,
00023 ::Compression::Buffer & target
00024 )
00025 {
00026 unsigned int max_length =
00027 static_cast <unsigned int> (source.length () * 1.01) + 600;
00028 target.length (static_cast <CORBA::ULong> (max_length));
00029
00030 int const retval = ::BZ2_bzBuffToBuffCompress (reinterpret_cast <char*>(target.get_buffer ()),
00031 &max_length,
00032 reinterpret_cast <char*>(const_cast<CORBA::Octet*>(source.get_buffer ())),
00033 source.length (),
00034 9,
00035 1,
00036 this->compression_level () * 25);
00037
00038 if (retval != BZ_OK)
00039 {
00040 throw ::Compression::CompressionException (retval, "");
00041 }
00042 else
00043 {
00044 target.length (static_cast <CORBA::ULong> (max_length));
00045 }
00046
00047
00048 this->update_stats (source.length (), target.length ());
00049 }
00050
00051 void
00052 Bzip2Compressor::decompress (
00053 const ::Compression::Buffer & source,
00054 ::Compression::Buffer & target)
00055 {
00056 unsigned int max_length = static_cast <unsigned int> (target.length ());
00057
00058 int const retval = ::BZ2_bzBuffToBuffDecompress (reinterpret_cast <char*>(target.get_buffer ()),
00059 &max_length,
00060 reinterpret_cast <char*>(const_cast<CORBA::Octet*>(source.get_buffer ())),
00061 source.length (),
00062 0,
00063 1);
00064
00065 if (retval != BZ_OK)
00066 {
00067 throw ::Compression::CompressionException (retval, "");
00068 }
00069 else
00070 {
00071 target.length (static_cast <CORBA::ULong> (max_length));
00072 }
00073 }
00074 }
00075
00076 TAO_END_VERSIONED_NAMESPACE_DECL