activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r910686 [6/8] - in /activemq/activemq-cpp/trunk/activemq-cpp: ./ src/main/ src/main/decaf/internal/util/zip/ src/main/decaf/util/zip/ src/test/ src/test/decaf/util/zip/
Date Tue, 16 Feb 2010 20:54:11 GMT
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/zip/zutil.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/zip/zutil.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/zip/zutil.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/zip/zutil.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,269 @@
+/* zutil.h -- internal interface and configuration of the compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+   part of the implementation of the compression library and is
+   subject to change. Applications should only use zlib.h.
+ */
+
+/* @(#) $Id$ */
+
+#ifndef ZUTIL_H
+#define ZUTIL_H
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+#ifdef STDC
+#  ifndef _WIN32_WCE
+#    include <stddef.h>
+#  endif
+#  include <string.h>
+#  include <stdlib.h>
+#endif
+#ifdef NO_ERRNO_H
+#   ifdef _WIN32_WCE
+      /* The Microsoft C Run-Time Library for Windows CE doesn't have
+       * errno.  We define it as a global variable to simplify porting.
+       * Its value is always 0 and should not be used.  We rename it to
+       * avoid conflict with other libraries that use the same workaround.
+       */
+#     define errno z_errno
+#   endif
+    extern int errno;
+#else
+#  ifndef _WIN32_WCE
+#    include <errno.h>
+#  endif
+#endif
+
+#ifndef local
+#  define local static
+#endif
+/* compile with -Dlocal if your debugger can't find static symbols */
+
+typedef unsigned char  uch;
+typedef uch FAR uchf;
+typedef unsigned short ush;
+typedef ush FAR ushf;
+typedef unsigned long  ulg;
+
+extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+/* (size given to avoid silly warnings with Visual C++) */
+
+#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
+
+#define ERR_RETURN(strm,err) \
+  return (strm->msg = (char*)ERR_MSG(err), (err))
+/* To be used only when the state is known to be valid */
+
+        /* common constants */
+
+#ifndef DEF_WBITS
+#  define DEF_WBITS MAX_WBITS
+#endif
+/* default windowBits for decompression. MAX_WBITS is for compression only */
+
+#if MAX_MEM_LEVEL >= 8
+#  define DEF_MEM_LEVEL 8
+#else
+#  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
+#endif
+/* default memLevel */
+
+#define STORED_BLOCK 0
+#define STATIC_TREES 1
+#define DYN_TREES    2
+/* The three kinds of block type */
+
+#define MIN_MATCH  3
+#define MAX_MATCH  258
+/* The minimum and maximum match lengths */
+
+#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+
+        /* target dependencies */
+
+#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
+#  define OS_CODE  0x00
+#  if defined(__TURBOC__) || defined(__BORLANDC__)
+#    if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+       /* Allow compilation with ANSI keywords only enabled */
+       void _Cdecl farfree( void *block );
+       void *_Cdecl farmalloc( unsigned long nbytes );
+#    else
+#      include <alloc.h>
+#    endif
+#  else /* MSC or DJGPP */
+#    include <malloc.h>
+#  endif
+#endif
+
+#ifdef AMIGA
+#  define OS_CODE  0x01
+#endif
+
+#if defined(VAXC) || defined(VMS)
+#  define OS_CODE  0x02
+#  define F_OPEN(name, mode) \
+     fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
+#endif
+
+#if defined(ATARI) || defined(atarist)
+#  define OS_CODE  0x05
+#endif
+
+#ifdef OS2
+#  define OS_CODE  0x06
+#  ifdef M_I86
+     #include <malloc.h>
+#  endif
+#endif
+
+#if defined(MACOS) || defined(TARGET_OS_MAC)
+#  define OS_CODE  0x07
+#  if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+#    include <unix.h> /* for fdopen */
+#  else
+#    ifndef fdopen
+#      define fdopen(fd,mode) NULL /* No fdopen() */
+#    endif
+#  endif
+#endif
+
+#ifdef TOPS20
+#  define OS_CODE  0x0a
+#endif
+
+#ifdef WIN32
+#  ifndef __CYGWIN__  /* Cygwin is Unix, not Win32 */
+#    define OS_CODE  0x0b
+#  endif
+#endif
+
+#ifdef __50SERIES /* Prime/PRIMOS */
+#  define OS_CODE  0x0f
+#endif
+
+#if defined(_BEOS_) || defined(RISCOS)
+#  define fdopen(fd,mode) NULL /* No fdopen() */
+#endif
+
+#if (defined(_MSC_VER) && (_MSC_VER > 600))
+#  if defined(_WIN32_WCE)
+#    define fdopen(fd,mode) NULL /* No fdopen() */
+#    ifndef _PTRDIFF_T_DEFINED
+       typedef int ptrdiff_t;
+#      define _PTRDIFF_T_DEFINED
+#    endif
+#  else
+#    define fdopen(fd,type)  _fdopen(fd,type)
+#  endif
+#endif
+
+        /* common defaults */
+
+#ifndef OS_CODE
+#  define OS_CODE  0x03  /* assume Unix */
+#endif
+
+#ifndef F_OPEN
+#  define F_OPEN(name, mode) fopen((name), (mode))
+#endif
+
+         /* functions */
+
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+#  ifndef HAVE_VSNPRINTF
+#    define HAVE_VSNPRINTF
+#  endif
+#endif
+#if defined(__CYGWIN__)
+#  ifndef HAVE_VSNPRINTF
+#    define HAVE_VSNPRINTF
+#  endif
+#endif
+#ifndef HAVE_VSNPRINTF
+#  ifdef MSDOS
+     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+        but for now we just assume it doesn't. */
+#    define NO_vsnprintf
+#  endif
+#  ifdef __TURBOC__
+#    define NO_vsnprintf
+#  endif
+#  ifdef WIN32
+     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+#    if !defined(vsnprintf) && !defined(NO_vsnprintf)
+#      define vsnprintf _vsnprintf
+#    endif
+#  endif
+#  ifdef __SASC
+#    define NO_vsnprintf
+#  endif
+#endif
+#ifdef VMS
+#  define NO_vsnprintf
+#endif
+
+#if defined(pyr)
+#  define NO_MEMCPY
+#endif
+#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
+ /* Use our own functions for small and medium model with MSC <= 5.0.
+  * You may have to use the same strategy for Borland C (untested).
+  * The __SC__ check is for Symantec.
+  */
+#  define NO_MEMCPY
+#endif
+#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
+#  define HAVE_MEMCPY
+#endif
+#ifdef HAVE_MEMCPY
+#  ifdef SMALL_MEDIUM /* MSDOS small or medium model */
+#    define zmemcpy _fmemcpy
+#    define zmemcmp _fmemcmp
+#    define zmemzero(dest, len) _fmemset(dest, 0, len)
+#  else
+#    define zmemcpy memcpy
+#    define zmemcmp memcmp
+#    define zmemzero(dest, len) memset(dest, 0, len)
+#  endif
+#else
+   extern void zmemcpy  OF((Bytef* dest, const Bytef* source, uInt len));
+   extern int  zmemcmp  OF((const Bytef* s1, const Bytef* s2, uInt len));
+   extern void zmemzero OF((Bytef* dest, uInt len));
+#endif
+
+/* Diagnostic functions */
+#ifdef DEBUG
+#  include <stdio.h>
+   extern int z_verbose;
+   extern void z_error    OF((char *m));
+#  define Assert(cond,msg) {if(!(cond)) z_error(msg);}
+#  define Trace(x) {if (z_verbose>=0) fprintf x ;}
+#  define Tracev(x) {if (z_verbose>0) fprintf x ;}
+#  define Tracevv(x) {if (z_verbose>1) fprintf x ;}
+#  define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
+#  define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
+#else
+#  define Assert(cond,msg)
+#  define Trace(x)
+#  define Tracev(x)
+#  define Tracevv(x)
+#  define Tracec(c,x)
+#  define Tracecv(c,x)
+#endif
+
+
+voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
+void   zcfree  OF((voidpf opaque, voidpf ptr));
+
+#define ZALLOC(strm, items, size) \
+           (*((strm)->zalloc))((strm)->opaque, (items), (size))
+#define ZFREE(strm, addr)  (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
+#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+
+#endif /* ZUTIL_H */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/zip/zutil.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Adler32.h"
+
+#include <decaf/internal/util/zip/zlib.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+Adler32::Adler32() {
+    this->reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Adler32::~Adler32() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32::reset() {
+    this->value = adler32( this->value, NULL, 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Adler32::getValue() const {
+    return this->value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32::update( const std::vector<unsigned char>& buffer ) {
+    this->update( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32::update( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    if( offset + length > buffer.size() ) {
+        throw IndexOutOfBoundsException(
+            __FILE__, __LINE__, "Given offset + length exceeds the length of the buffer." );
+    }
+
+    this->update( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32::update( int byte ) {
+    this->value = adler32( this->value, (const Bytef*)&byte, 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32::update( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    if( offset + length > size ) {
+        throw IndexOutOfBoundsException(
+            __FILE__, __LINE__, "Given offset + length exceeds the length of the buffer." );
+    }
+
+    this->value = adler32( this->value, (const Bytef*)( buffer + offset ), length );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_ZIP_ADLER32_H_
+#define _DECAF_UTIL_ZIP_ADLER32_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/util/zip/Checksum.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    /**
+     * Clas that can be used to compute an Adler-32 Checksum for a data stream.  The
+     * Alder-32 checksum trades reliability for speed over the CRC-32 algorithm.
+     *
+     * @since 1.0
+     */
+    class DECAF_API Adler32 : public Checksum {
+    private:
+
+        long long value;
+
+    public:
+
+        Adler32();
+
+        virtual ~Adler32();
+
+        /**
+         * @returns the current checksum value.
+         */
+        virtual long long getValue() const;
+
+        /**
+         * Reset the checksum to its initial value.
+         */
+        virtual void reset();
+
+        /**
+         * Updates the current checksum with the specified vector of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer );
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param size
+         *      The size of the passed buffer.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw NullPointerException if the passed buffer is NULL.
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const unsigned char* buffer, std::size_t size,
+                             std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Updates the current checksum with the specified byte value.
+         *
+         * @param byte
+         *      The byte value to update the current Checksum with (0..255).
+         */
+        virtual void update( int byte );
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_ADLER32_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Adler32.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CRC32.h"
+
+#include <decaf/internal/util/zip/zlib.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+CRC32::CRC32() {
+    this->reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CRC32::~CRC32() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32::reset() {
+    this->value = crc32( this->value, NULL, 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long CRC32::getValue() const {
+    return this->value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32::update( const std::vector<unsigned char>& buffer ) {
+    this->update( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32::update( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    if( offset + length > buffer.size() ) {
+        throw IndexOutOfBoundsException(
+            __FILE__, __LINE__, "Given offset + length exceeds the length of the buffer." );
+    }
+
+    this->update( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32::update( int byte ) {
+    this->value = crc32( this->value, (const Bytef*)&byte, 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32::update( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    if( offset + length > size ) {
+        throw IndexOutOfBoundsException(
+            __FILE__, __LINE__, "Given offset + length exceeds the length of the buffer." );
+    }
+
+    this->value = crc32( this->value, (const Bytef*)( buffer + offset ), length );
+}
+
+
+

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_ZIP_CRC32_H_
+#define _DECAF_UTIL_ZIP_CRC32_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/util/zip/Checksum.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    /**
+     * Class that can be used to compute a CRC-32 checksum for a data stream.
+     *
+     * @since 1.0
+     */
+    class DECAF_API CRC32 : public Checksum {
+    private:
+
+        long long value;
+
+    public:
+
+        CRC32();
+
+        virtual ~CRC32();
+
+        /**
+         * @returns the current checksum value.
+         */
+        virtual long long getValue() const;
+
+        /**
+         * Reset the checksum to its initial value.
+         */
+        virtual void reset();
+
+        /**
+         * Updates the current checksum with the specified vector of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer );
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param size
+         *      The size of the passed buffer.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw NullPointerException if the passed buffer is NULL.
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const unsigned char* buffer, std::size_t size,
+                             std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Updates the current checksum with the specified byte value.
+         *
+         * @param byte
+         *      The byte value to update the current Checksum with (0..255).
+         */
+        virtual void update( int byte );
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_CRC32_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/CRC32.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Checksum.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Checksum.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Checksum.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Checksum.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_ZIP_CHECKSUM_H_
+#define _DECAF_UTIL_ZIP_CHECKSUM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#include <vector>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    /**
+     * An interface used to represent Checksum values in the Zip package.
+     *
+     * @since 1.0
+     */
+    class DECAF_API Checksum {
+    public:
+
+        virtual ~Checksum() {}
+
+        /**
+         * @returns the current checksum value.
+         */
+        virtual long long getValue() const = 0;
+
+        /**
+         * Reset the checksum to its initial value.
+         */
+        virtual void reset() = 0;
+
+        /**
+         * Updates the current checksum with the specified vector of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer ) = 0;
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * Updates the current checksum with the specified array of bytes.
+         *
+         * @param buffer
+         *      The buffer to read the updated bytes from.
+         * @param size
+         *      The size of the passed buffer.
+         * @param offset
+         *      The position in the buffer to start reading.
+         * @param length
+         *      The amount of data to read from the byte buffer.
+         *
+         * @throw NullPointerException if the passed buffer is NULL.
+         * @throw IndexOutOfBoundsException if offset + length > size of the buffer.
+         */
+        virtual void update( const unsigned char* buffer, std::size_t size,
+                             std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+        /**
+         * Updates the current checksum with the specified byte value.
+         *
+         * @param byte
+         *      The byte value to update the current Checksum with (0..255).
+         */
+        virtual void update( int byte ) = 0;
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_CHECKSUM_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Checksum.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _DECAF_UTIL_ZIP_DATAFORMATEXCEPTION_H
+#define _DECAF_UTIL_ZIP_DATAFORMATEXCEPTION_H
+
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace util{
+namespace zip{
+
+    /*
+     * Signals that an I/O exception of some sort has occurred.
+     */
+    class DECAF_API DataFormatException : public lang::Exception {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        DataFormatException() throw() {}
+
+        /**
+         * Copy Constructor
+         * @param ex the exception to copy
+         */
+        DataFormatException( const lang::Exception& ex ) throw()
+        : lang::Exception() {
+            *(lang::Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         * @param ex the exception to copy, which is an instance of this type
+         */
+        DataFormatException( const DataFormatException& ex ) throw()
+        : lang::Exception() {
+            *(lang::Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param cause The exception that was the cause for this one to be thrown.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        DataFormatException( const char* file, const int lineNumber,
+                             const std::exception* cause,
+                             const char* msg, ... ) throw() : lang::Exception( cause )
+        {
+            va_list vargs;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Constructor
+         * @param cause Pointer to the exception that caused this one to
+         * be thrown, the object is cloned caller retains ownership.
+         */
+        DataFormatException( const std::exception* cause ) throw() : lang::Exception( cause ) {}
+
+        /**
+         * Constructor
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        DataFormatException( const char* file, const int lineNumber,
+                             const char* msg, ... ) throw()
+        : lang::Exception() {
+            va_list vargs;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         *
+         * @return a new instance of an Exception that is a copy of this instance.
+         */
+        virtual DataFormatException* clone() const {
+            return new DataFormatException( *this );
+        }
+
+        virtual ~DataFormatException() throw() {}
+
+    };
+
+}}}
+
+#endif /*_DECAF_UTIL_ZIP_DATAFORMATEXCEPTION_H*/

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DataFormatException.h
------------------------------------------------------------------------------
    svn:executable = *

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,470 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Deflater.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include <decaf/internal/util/zip/zlib.h>
+
+#include <decaf/lang/exceptions/RuntimeException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace util{
+namespace zip{
+
+    class DeflaterData {
+    public:
+
+        int level;
+        bool nowrap;
+        int strategy;
+        int flush;
+        bool finished;
+        bool ended;
+
+        unsigned char* inputBuffer;
+        std::size_t inRead;
+        std::size_t inLength;
+
+        z_stream* stream;
+
+    public:
+
+        static void initZLibDeflate( DeflaterData* handle, int level, bool nowrap = false ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Compression Library." );
+            }
+
+            handle->stream = new z_stream;
+            handle->ended = false;
+            handle->level = level;
+            handle->strategy = 0;
+            handle->nowrap = nowrap;
+            handle->finished = false;
+            handle->flush = Z_NO_FLUSH;
+
+            // Init the ZLib stream to defaults
+            handle->stream->zalloc = Z_NULL;
+            handle->stream->zfree = Z_NULL;
+            handle->stream->opaque = Z_NULL;
+            handle->stream->avail_in = 0;
+            handle->stream->next_in = Z_NULL;
+
+            int result = Z_OK;
+            if( nowrap == false ) {
+                result = deflateInit( handle->stream, handle->level );
+            } else {
+
+                // Turn off ZLib header wrapping and encode raw.  Attempts
+                // to set all other values to their normal defaults.
+                result = deflateInit2( handle->stream,
+                                       handle->level,
+                                       Z_DEFLATED,
+                                       -15, 8,
+                                       Z_DEFAULT_STRATEGY );
+            }
+
+            if( result != Z_OK ) {
+                throw RuntimeException(
+                    __FILE__, __LINE__, "Error While initializing the Compression Library." );
+            }
+        }
+
+        static void finishZlibDeflate( DeflaterData* handle ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Compression Library." );
+            }
+
+            handle->ended = true;
+
+            if( handle->stream != NULL ) {
+
+                // Shutdown the ZLib stream
+                deflateEnd( handle->stream );
+                delete handle->stream;
+                handle->stream = NULL;
+            }
+        }
+
+        static void resetZlibStream( DeflaterData* handle ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Compression Library." );
+            }
+
+            if( handle->stream != NULL ) {
+
+                handle->finished = false;
+                handle->flush = Z_NO_FLUSH;
+                handle->ended = false;
+                handle->flush = Z_NO_FLUSH;
+
+                // Ask ZLib to do the reset.
+                deflateReset( handle->stream );
+
+                // Clear any old data that might still be around.
+                handle->stream->opaque = Z_NULL;
+                handle->stream->avail_in = 0;
+                handle->stream->next_in = Z_NULL;
+            }
+        }
+
+    };
+
+}}}
+
+////////////////////////////////////////////////////////////////////////////////
+const int Deflater::BEST_COMPRESSION = 9;
+const int Deflater::BEST_SPEED = 1;
+const int Deflater::NO_COMPRESSION = 0;
+const int Deflater::DEFAULT_COMPRESSION = -1;
+
+const int Deflater::DEFAULT_STRATEGY = 0;
+const int Deflater::DEFLATED = 0;
+const int Deflater::FILTERED = 1;
+const int Deflater::HUFFMAN_ONLY = 2;
+
+////////////////////////////////////////////////////////////////////////////////
+Deflater::Deflater( int level, bool nowrap ) {
+
+    if( level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Compression level passed was Invalid: %d", level );
+    }
+
+    this->data = new DeflaterData();
+
+    // Initialize all the ZLib structures.
+    DeflaterData::initZLibDeflate( this->data, level, nowrap );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Deflater::Deflater() {
+
+    this->data = new DeflaterData();
+
+    // Initialize all the ZLib structures.
+    DeflaterData::initZLibDeflate( this->data, DEFAULT_COMPRESSION );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Deflater::~Deflater() {
+    try{
+        this->end();
+        delete this->data;
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setInput( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Buffer passed cannot be NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Deflator has already been ended." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Given offset + length greater than the size of the buffer." );
+        }
+
+
+        // We can only change the level and strategy once an entire block of data is compressed.
+        if( this->data->stream->next_in == NULL ) {
+            deflateParams( this->data->stream, this->data->level, this->data->strategy );
+        }
+
+        this->data->stream->avail_in = length;
+        this->data->stream->next_in = (Bytef*)( buffer + offset );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setInput( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    this->setInput( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setInput( const std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setInput( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setDictionary( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Buffer passed cannot be NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Deflator has already been ended." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Given offset + length greater than the size of the buffer." );
+        }
+
+        // From the ZLib documentation.
+        // deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
+        // (such as NULL dictionary) or the stream state is inconsistent (for example if deflate has
+        // already been called for this stream or if the compression method is bsort).
+        // deflateSetDictionary does not perform any compression: this will be done by deflate().
+        if( deflateSetDictionary( this->data->stream, buffer + offset, length ) != Z_OK ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "Deflator could not accept the dictionary." );
+        }
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setDictionary( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    this->setDictionary( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setDictionary( const std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setDictionary( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setStrategy( int strategy )
+    throw( decaf::lang::exceptions::IllegalArgumentException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    if( strategy < DEFAULT_STRATEGY || strategy > HUFFMAN_ONLY ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Strategy value {%d} is not valid.", strategy );
+    }
+
+    if( this->data->stream == NULL && !this->data->ended ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator is in an invalid state." );
+    }
+
+    this->data->strategy = strategy;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::setLevel( int level )
+    throw( decaf::lang::exceptions::IllegalArgumentException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    if( level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Strategy value {%d} is not valid.", level );
+    }
+
+    if( this->data->stream == NULL && !this->data->ended ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator is in an invalid state." );
+    }
+
+    this->data->level = level;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Deflater::needsInput() const {
+    if( this->data->stream == NULL ) {
+        return false;
+    }
+
+    return this->data->stream->avail_in == 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::finish() {
+    this->data->flush = Z_FINISH;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Deflater::finished() const {
+    return this->data->finished;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Deflater::deflate( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Buffer passed cannot be NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Deflator has already been ended." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Given offset + length greater than the size of the buffer." );
+        }
+
+        std::size_t outStart = this->data->stream->total_out;
+
+        this->data->stream->next_out = buffer + offset;
+        this->data->stream->avail_out = length;
+
+        // Call ZLib and then process the resulting data to figure out what happened.
+        int result = ::deflate( this->data->stream, this->data->flush );
+
+        if( result == Z_STREAM_END ) {
+            this->data->finished = true;
+        }
+
+        return this->data->stream->total_out - outStart;
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Deflater::deflate( std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    return this->deflate( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Deflater::deflate( std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalStateException ){
+
+    return this->deflate( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Deflater::getAdler() const throw( decaf::lang::exceptions::IllegalStateException ) {
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator has already been ended." );
+    }
+
+    return this->data->stream->adler;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Deflater::getBytesRead() const throw( decaf::lang::exceptions::IllegalStateException ) {
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator has already been ended." );
+    }
+
+    return this->data->stream->total_in;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Deflater::getBytesWritten() const throw( decaf::lang::exceptions::IllegalStateException ) {
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator has already been ended." );
+    }
+
+    return this->data->stream->total_out;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::reset() throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Deflator has already been ended." );
+    }
+
+    DeflaterData::resetZlibStream( this->data );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Deflater::end() {
+
+    if( this->data ) {
+        DeflaterData::finishZlibDeflate( this->data );
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTI_ZIP_DEFLATER_H_
+#define _DECAF_UTI_ZIP_DEFLATER_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#include <vector>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    class DeflaterData;
+
+    /**
+     * This class compresses data using the <i>DEFLATE</i> algorithm (see <a
+     * href="http://www.gzip.org/algorithm.txt">specification</a>).
+     *
+     * Basically this class is part of the API to the stream based ZLIB compression
+     * library and is used as such by {@code DeflaterOutputStream} and its
+     * descendants.
+     *
+     * The typical usage of a {@code Deflater} instance outside this package
+     * consists of a specific call to one of its constructors before being passed to
+     * an instance of {@code DeflaterOutputStream}.
+     *
+     * @see DeflaterOutputStream
+     * @see Inflater
+     * @since 1.0
+     */
+    class DECAF_API Deflater {
+    public:
+
+        /**
+         * Compression level for fastest compression.
+         */
+        static const int BEST_SPEED;
+
+        /**
+         * Compression level for best compression.
+         */
+        static const int BEST_COMPRESSION;
+
+        /**
+         * Default compression level.
+         */
+        static const int DEFAULT_COMPRESSION;
+
+        /**
+         * Compression method for the deflate algorithm (the only one currently supported).
+         */
+        static const int DEFLATED;
+
+        /**
+         * Compression level for no compression. .
+         */
+        static const int NO_COMPRESSION;
+
+        /**
+         * Compression strategy best used for data consisting mostly of small values
+         * with a somewhat random distribution. Forces more Huffman coding and less
+         * string matching.
+         */
+        static const int FILTERED;
+
+        /**
+         * Compression strategy for Huffman coding only.
+         */
+        static const int HUFFMAN_ONLY;
+
+        /**
+         * Default compression strategy.
+         */
+        static const int DEFAULT_STRATEGY;
+
+    private:
+
+        // Class internal data used during compression.
+        DeflaterData* data;
+
+    public:
+
+        /**
+         * Creates a new compressor using the specified compression level. If 'nowrap' is true then
+         * the ZLIB header and checksum fields will not be used in order to support the compression
+         * format used in both GZIP and PKZIP.
+         *
+         * @param level
+         *      The compression level to use (0-9).
+         * @param nowrap
+         *      If true uses GZip compatible compression (defaults to false).
+         */
+        Deflater( int level, bool nowrap = false );
+
+        /**
+         * Creates a new compressor with the default compression level. Compressed data will be
+         * generated in ZLIB format.
+         */
+        Deflater();
+
+        virtual ~Deflater();
+
+        /**
+         * Sets input data for compression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for compression.
+         * @param size
+         *      The size in bytes of the buffer passed.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets input data for compression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for compression.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets input data for compression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for compression.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets preset dictionary for compression. A preset dictionary is used when the
+         * history buffer can be predetermined. When the data is later uncompressed with
+         * Inflater.inflate(), Inflater.getAdler() can be called in order to get the
+         * Adler-32 value of the dictionary required for decompression.
+         *
+         * @param buffer
+         *      The buffer containing the preset dictionary.
+         * @param size
+         *      The size of the passed dictionary buffer.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setDictionary( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets preset dictionary for compression. A preset dictionary is used when the
+         * history buffer can be predetermined. When the data is later uncompressed with
+         * Inflater.inflate(), Inflater.getAdler() can be called in order to get the
+         * Adler-32 value of the dictionary required for decompression.
+         *
+         * @param buffer
+         *      The buffer containing the preset dictionary.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setDictionary( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets preset dictionary for compression. A preset dictionary is used when the
+         * history buffer can be predetermined. When the data is later uncompressed with
+         * Inflater.inflate(), Inflater.getAdler() can be called in order to get the
+         * Adler-32 value of the dictionary required for decompression.
+         *
+         * @param buffer
+         *      The buffer containing the preset dictionary.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        void setDictionary( const std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets the compression strategy to the specified value.
+         *
+         * @param strategy
+         *      The new Compression strategy to use.
+         *
+         * @throws IllegalArgumentException if the strategy value is invalid.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setStrategy( int strategy )
+            throw( decaf::lang::exceptions::IllegalArgumentException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets the compression level to the specified value.
+         *
+         * @param level
+         *      The new Compression level to use.
+         *
+         * @throws IllegalArgumentException if the level value is invalid.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setLevel( int level )
+            throw( decaf::lang::exceptions::IllegalArgumentException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @return true if the input data buffer is empty and setInput() should be called in
+         *         order to provide more input
+         */
+        bool needsInput() const;
+
+        /**
+         * When called, indicates that compression should end with the current contents of
+         * the input buffer.
+         */
+        void finish();
+
+        /**
+         * @return true if the end of the compressed data output stream has been reached.
+         */
+        bool finished() const;
+
+        /**
+         * Fills specified buffer with compressed data. Returns actual number of bytes of
+         * compressed data. A return value of 0 indicates that needsInput() should be called
+         * in order to determine if more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         * @param size
+         *      The size of the passed buffer.
+         * @param offset
+         *      The position in the Buffer to start writing at.
+         * @param length
+         *      The maximum number of byte of data to write.
+         *
+         * @returns the actual number of bytes of compressed data.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        std::size_t deflate( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Fills specified buffer with compressed data. Returns actual number of bytes of
+         * compressed data. A return value of 0 indicates that needsInput() should be called
+         * in order to determine if more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         * @param offset
+         *      The position in the Buffer to start writing at.
+         * @param length
+         *      The maximum number of byte of data to write.
+         *
+         * @returns the actual number of bytes of compressed data.
+         *
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        std::size_t deflate( std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Fills specified buffer with compressed data. Returns actual number of bytes of
+         * compressed data. A return value of 0 indicates that needsInput() should be called
+         * in order to determine if more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         *
+         * @returns the actual number of bytes of compressed data.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        std::size_t deflate( std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @returns the ADLER-32 value of the uncompressed data.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        std::size_t getAdler() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @returns the total number of uncompressed bytes input so far.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        long long getBytesRead() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @return the total number of compressed bytes output so far.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        long long getBytesWritten() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Resets deflater so that a new set of input data can be processed. Keeps current compression
+         * level and strategy settings.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        void reset() throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Closes the compressor and discards any unprocessed input. This method should be called
+         * when the compressor is no longer being used, but will also be called automatically by the
+         * destructor. Once this method is called, the behavior of the Deflater object is undefined.
+         */
+        void end();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTI_ZIP_DEFLATER_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Deflater.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "DeflaterOutputStream.h"
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+DeflaterOutputStream::DeflaterOutputStream( OutputStream* outputStream, bool own ) :
+    FilterOutputStream( outputStream, own ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DeflaterOutputStream::~DeflaterOutputStream() {
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_UTIL_ZIP_DEFLATEROUTPUTSTREAM_H_
+#define _DECAF_UTIL_ZIP_DEFLATEROUTPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/FilterOutputStream.h>
+#include <decaf/io/IOException.h>
+#include <decaf/util/zip/Deflater.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    /**
+     *
+     */
+    class DECAF_API DeflaterOutputStream : public decaf::io::FilterOutputStream {
+    public:
+
+        DeflaterOutputStream( decaf::io::OutputStream* outputStream, bool own = false );
+
+        virtual ~DeflaterOutputStream();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_DEFLATEROUTPUTSTREAM_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,446 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Inflater.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include <decaf/internal/util/zip/zlib.h>
+
+#include <decaf/lang/exceptions/RuntimeException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace util{
+namespace zip{
+
+    class InflaterData {
+    public:
+
+        bool nowrap;
+        bool finished;
+        bool needDictionary;
+        int flush;
+
+        z_stream* stream;
+
+    public:
+
+        static void initZlibInflate( InflaterData* handle, bool nowrap = false ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Decompression Library." );
+            }
+
+            handle->stream = new z_stream;
+            handle->finished = false;
+            handle->needDictionary = false;
+            handle->flush = Z_NO_FLUSH;
+            handle->nowrap = nowrap;
+
+            // Init the ZLib stream to defaults
+            handle->stream->zalloc = Z_NULL;
+            handle->stream->zfree = Z_NULL;
+            handle->stream->opaque = Z_NULL;
+            handle->stream->avail_in = 0;
+            handle->stream->next_in = Z_NULL;
+
+            int result = Z_OK;
+            if( nowrap == false ) {
+                result = inflateInit( handle->stream );
+            } else {
+                // Disable the ZLib header.
+                result = inflateInit2( handle->stream, -15 );
+            }
+
+            if( result != Z_OK ) {
+                throw RuntimeException(
+                    __FILE__, __LINE__, "Error While initializing the Decompression Library." );
+            }
+        }
+
+        static void finishZlibDeflate( InflaterData* handle ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Decompression Library." );
+            }
+
+            if( handle->stream != NULL ) {
+
+                // Shutdown the ZLib stream
+                inflateEnd( handle->stream );
+                delete handle->stream;
+                handle->stream = NULL;
+            }
+        }
+
+        static void resetZlibStream( InflaterData* handle ) {
+
+            if( handle == NULL ) {
+                throw NullPointerException(
+                    __FILE__, __LINE__, "Error While initializing the Decompression Library." );
+            }
+
+            if( handle->stream != NULL ) {
+
+                handle->finished = false;
+                handle->needDictionary = false;
+                handle->flush = Z_NO_FLUSH;
+
+                // Ask ZLib to do the reset.
+                inflateReset( handle->stream );
+
+                // clear any old data
+                handle->stream->opaque = Z_NULL;
+                handle->stream->avail_in = 0;
+                handle->stream->next_in = Z_NULL;
+            }
+        }
+    };
+
+}}}
+
+////////////////////////////////////////////////////////////////////////////////
+Inflater::Inflater( bool nowrap ) {
+
+    this->data = new InflaterData();
+
+    InflaterData::initZlibInflate( this->data, nowrap );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inflater::Inflater() {
+
+    this->data = new InflaterData();
+
+    InflaterData::initZlibInflate( this->data );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inflater::~Inflater() {
+    try{
+        this->end();
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setInput( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Passed Buffer was NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Inflater end method has already been called." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "The offset + length given is greater than the specified buffer size." );
+        }
+
+        this->data->stream->avail_in = length;
+        this->data->stream->next_in = (Bytef*)( buffer + offset );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setInput( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setInput( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setInput( const std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setInput( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Inflater::getRemaining() const {
+
+    if( this->data->stream != NULL ) {
+        return this->data->stream->avail_in;
+    }
+
+    return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setDictionary( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalArgumentException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Passed Buffer was NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Inflater end method has already been called." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "The offset + length given is greater than the specified buffer size." );
+        }
+
+        // From the ZLib documentation
+        // inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a parameter is invalid (such
+        // as NULL dictionary) or the stream state is inconsistent, Z_DATA_ERROR if the given dictionary
+        // doesn't match the expected one (incorrect adler32 value). inflateSetDictionary does not
+        // perform any decompression: this will be done by subsequent calls of inflate().
+        int result = inflateSetDictionary( this->data->stream, buffer + offset, length );
+        if( result != Z_OK ) {
+            throw IllegalArgumentException(
+                __FILE__, __LINE__, "Dictionary given does not match required checksum value." );
+        }
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCH_RETHROW( IllegalArgumentException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setDictionary( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException,
+           decaf::lang::exceptions::IllegalArgumentException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setDictionary( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::setDictionary( const std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalArgumentException,
+           decaf::lang::exceptions::IllegalStateException ) {
+
+    if( buffer.empty() ) {
+        return;
+    }
+
+    this->setDictionary( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inflater::needsInput() const {
+
+    if( this->data->stream == NULL ) {
+        return false;
+    }
+
+    return this->data->stream->avail_in == 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inflater::needsDictionary() const {
+    return this->data->needDictionary;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::finish() {
+    this->data->flush = Z_FINISH;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inflater::finished() const {
+    return this->data->finished;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Inflater::inflate( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::NullPointerException,
+           decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException,
+           decaf::util::zip::DataFormatException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__, "Passed Buffer was NULL." );
+        }
+
+        if( this->data->stream == NULL ) {
+            throw IllegalStateException(
+                __FILE__, __LINE__, "The Inflater end method has already been called." );
+        }
+
+        if( offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "The offset + length given is greater than the specified buffer size." );
+        }
+
+        std::size_t outStart = this->data->stream->total_out;
+
+        this->data->stream->next_out = buffer + offset;
+        this->data->stream->avail_out = length;
+
+        // Call ZLib and then process the resulting data to figure out what happened.
+        int result = ::inflate( this->data->stream, this->data->flush );
+
+        if( result == Z_STREAM_END ) {
+            this->data->finished = true;
+        } else if( result == Z_NEED_DICT ) {
+
+            if( this->needsDictionary() ) {
+                throw DataFormatException(
+                    __FILE__, __LINE__, "Inflate cannot proceed until a Dictionary is set." );
+            }
+
+            this->data->needDictionary = true;
+        } else if( result == Z_DATA_ERROR ) {
+            throw DataFormatException(
+                __FILE__, __LINE__, "Inflate failed because a block of invalid data was found." );
+        }
+
+        return this->data->stream->total_out - outStart;
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_RETHROW( DataFormatException )
+    DECAF_CATCH_RETHROW( IllegalStateException )
+    DECAF_CATCHALL_THROW( IllegalStateException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Inflater::inflate( std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::IllegalStateException,
+           decaf::util::zip::DataFormatException ) {
+
+    if( buffer.empty() ) {
+        return 0;
+    }
+
+    return this->inflate( &buffer[0], buffer.size(), offset, length );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Inflater::inflate( std::vector<unsigned char>& buffer )
+    throw( decaf::lang::exceptions::IllegalStateException,
+           decaf::util::zip::DataFormatException ){
+
+    if( buffer.empty() ) {
+        return 0;
+    }
+
+    return this->inflate( &buffer[0], buffer.size(), 0, buffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t Inflater::getAdler() const throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Inflater has already been ended." );
+    }
+
+    return this->data->stream->adler;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Inflater::getBytesRead() const throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Inflater has already been ended." );
+    }
+
+    return this->data->stream->total_in;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Inflater::getBytesWritten() const throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Inflater has already been ended." );
+    }
+
+    return this->data->stream->total_out;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::reset() throw( decaf::lang::exceptions::IllegalStateException ) {
+
+    if( this->data->stream == NULL ) {
+        throw IllegalStateException(
+            __FILE__, __LINE__, "The Inflater has already been ended." );
+    }
+
+    InflaterData::resetZlibStream( this->data );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inflater::end() {
+
+    if( this->data ) {
+        InflaterData::finishZlibDeflate( this->data );
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.cpp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message