Go to the documentation of this file.00001 #include "ZlibCompressor.h"
00002
00003 ACE_RCSID (ZLIB,
00004 ZlibCompressor,
00005 "$Id: ZlibCompressor.cpp 84846 2009-03-16 18:37:44Z msmit $")
00006
00007 #include "zlib.h"
00008
00009 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 namespace TAO
00012 {
00013 ZlibCompressor::ZlibCompressor (
00014 ::Compression::CompressionLevel compression_level,
00015 ::Compression::CompressorFactory_ptr compressor_factory) :
00016 BaseCompressor (compression_level, compressor_factory)
00017 {
00018 }
00019
00020 void
00021 ZlibCompressor::compress (
00022 const ::Compression::Buffer & source,
00023 ::Compression::Buffer & target
00024 )
00025 {
00026 uLongf max_length =
00027 static_cast <uLongf> (source.length () * 1.001) + 12;
00028 target.length (static_cast <CORBA::ULong> (max_length));
00029
00030 int const retval = ::compress2 (reinterpret_cast <Bytef*>(target.get_buffer ()),
00031 &max_length,
00032 reinterpret_cast <const Bytef*>(source.get_buffer ()),
00033 source.length (),
00034 this->compression_level ());
00035
00036 if (retval != Z_OK)
00037 {
00038 throw ::Compression::CompressionException (retval, ::zError (retval));
00039 }
00040 else
00041 {
00042 target.length (static_cast <CORBA::ULong> (max_length));
00043 }
00044
00045
00046 this->update_stats (source.length (), target.length ());
00047 }
00048
00049 void
00050 ZlibCompressor::decompress (
00051 const ::Compression::Buffer & source,
00052 ::Compression::Buffer & target)
00053 {
00054 uLongf max_length = static_cast <uLongf> (target.length ());
00055 int const retval = uncompress (reinterpret_cast <Bytef*>(target.get_buffer ()),
00056 &max_length,
00057 reinterpret_cast <const Bytef*>(source.get_buffer ()),
00058 source.length ());
00059
00060 if (retval != Z_OK)
00061 {
00062 throw ::Compression::CompressionException (retval, "");
00063 }
00064 else
00065 {
00066 target.length (static_cast <CORBA::ULong> (max_length));
00067 }
00068 }
00069 }
00070
00071 TAO_END_VERSIONED_NAMESPACE_DECL