activemq-cpp-3.6.0
decaf::util::zip::Deflater Class Reference

This class compresses data using the DEFLATE algorithm (see specification). More...

#include <src/main/decaf/util/zip/Deflater.h>

Public Member Functions

 Deflater (int level, bool nowrap=false)
 Creates a new compressor using the specified compression level.
 Deflater ()
 Creates a new compressor with the default compression level.
virtual ~Deflater ()
void setInput (const unsigned char *buffer, int size, int offset, int length)
 Sets input data for compression.
void setInput (const std::vector< unsigned char > &buffer, int offset, int length)
 Sets input data for compression.
void setInput (const std::vector< unsigned char > &buffer)
 Sets input data for compression.
void setDictionary (const unsigned char *buffer, int size, int offset, int length)
 Sets preset dictionary for compression.
void setDictionary (const std::vector< unsigned char > &buffer, int offset, int length)
 Sets preset dictionary for compression.
void setDictionary (const std::vector< unsigned char > &buffer)
 Sets preset dictionary for compression.
void setStrategy (int strategy)
 Sets the compression strategy to the specified value.
void setLevel (int level)
 Sets the compression level to the specified value.
bool needsInput () const
void finish ()
 When called, indicates that compression should end with the current contents of the input buffer.
bool finished () const
int deflate (unsigned char *buffer, int size, int offset, int length)
 Fills specified buffer with compressed data.
int deflate (std::vector< unsigned char > &buffer, int offset, int length)
 Fills specified buffer with compressed data.
int deflate (std::vector< unsigned char > &buffer)
 Fills specified buffer with compressed data.
long long getAdler () const
long long getBytesRead () const
long long getBytesWritten () const
void reset ()
 Resets deflater so that a new set of input data can be processed.
void end ()
 Closes the compressor and discards any unprocessed input.

Static Public Attributes

static const int BEST_SPEED
 Compression level for fastest compression.
static const int BEST_COMPRESSION
 Compression level for best compression.
static const int DEFAULT_COMPRESSION
 Default compression level.
static const int DEFLATED
 Compression method for the deflate algorithm (the only one currently supported).
static const int NO_COMPRESSION
 Compression level for no compression.
static const int FILTERED
 Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.
static const int HUFFMAN_ONLY
 Compression strategy for Huffman coding only.
static const int DEFAULT_STRATEGY
 Default compression strategy.

Detailed Description

This class compresses data using the DEFLATE algorithm (see specification).

Basically this class is part of the API to the stream based ZLIB compression library and is used as such by DeflaterOutputStream and its descendants.

The typical usage of a Deflater instance outside this package consists of a specific call to one of its constructors before being passed to an instance of DeflaterOutputStream.

See Also
DeflaterOutputStream
Inflater
Since
1.0

Constructor & Destructor Documentation

decaf::util::zip::Deflater::Deflater ( int  level,
bool  nowrap = false 
)

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.

Parameters
levelThe compression level to use (0-9).
nowrapIf true uses GZip compatible compression (defaults to false).
decaf::util::zip::Deflater::Deflater ( )

Creates a new compressor with the default compression level.

Compressed data will be generated in ZLIB format.

virtual decaf::util::zip::Deflater::~Deflater ( )
virtual

Member Function Documentation

int decaf::util::zip::Deflater::deflate ( unsigned char *  buffer,
int  size,
int  offset,
int  length 
)

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.

Parameters
bufferThe Buffer to write the compressed data to.
sizeThe size of the passed buffer.
offsetThe position in the Buffer to start writing at.
lengthThe maximum number of byte of data to write.
Returns
the actual number of bytes of compressed data.
Exceptions
NullPointerExceptionif buffer is NULL.
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
int decaf::util::zip::Deflater::deflate ( std::vector< unsigned char > &  buffer,
int  offset,
int  length 
)

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.

Parameters
bufferThe Buffer to write the compressed data to.
offsetThe position in the Buffer to start writing at.
lengthThe maximum number of byte of data to write.
Returns
the actual number of bytes of compressed data.
Exceptions
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
int decaf::util::zip::Deflater::deflate ( std::vector< unsigned char > &  buffer)

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.

Parameters
bufferThe Buffer to write the compressed data to.
Returns
the actual number of bytes of compressed data.
Exceptions
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::end ( )

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 decaf::util::zip::Deflater::finish ( )

When called, indicates that compression should end with the current contents of the input buffer.

bool decaf::util::zip::Deflater::finished ( ) const
Returns
true if the end of the compressed data output stream has been reached.
long long decaf::util::zip::Deflater::getAdler ( ) const
Returns
the ADLER-32 value of the uncompressed data.
Exceptions
IllegalStateExceptionif in the end state.
long long decaf::util::zip::Deflater::getBytesRead ( ) const
Returns
the total number of uncompressed bytes input so far.
Exceptions
IllegalStateExceptionif in the end state.
long long decaf::util::zip::Deflater::getBytesWritten ( ) const
Returns
the total number of compressed bytes output so far.
Exceptions
IllegalStateExceptionif in the end state.
bool decaf::util::zip::Deflater::needsInput ( ) const
Returns
true if the input data buffer is empty and setInput() should be called in order to provide more input
void decaf::util::zip::Deflater::reset ( )

Resets deflater so that a new set of input data can be processed.

Keeps current compression level and strategy settings.

Exceptions
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setDictionary ( const unsigned char *  buffer,
int  size,
int  offset,
int  length 
)

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.

Parameters
bufferThe buffer containing the preset dictionary.
sizeThe size of the passed dictionary buffer.
offsetThe position in the Buffer to start reading from.
lengthThe number of bytes to read from the input buffer.
Exceptions
NullPointerExceptionif buffer is NULL.
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setDictionary ( const std::vector< unsigned char > &  buffer,
int  offset,
int  length 
)

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.

Parameters
bufferThe buffer containing the preset dictionary.
offsetThe position in the Buffer to start reading from.
lengthThe number of bytes to read from the input buffer.
Exceptions
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setDictionary ( const std::vector< unsigned char > &  buffer)

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.

Parameters
bufferThe buffer containing the preset dictionary.
Exceptions
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setInput ( const unsigned char *  buffer,
int  size,
int  offset,
int  length 
)

Sets input data for compression.

This should be called whenever needsInput() returns true indicating that more input data is required.

Parameters
bufferThe Buffer to read in for compression.
sizeThe size in bytes of the buffer passed.
offsetThe position in the Buffer to start reading from.
lengthThe number of bytes to read from the input buffer.
Exceptions
NullPointerExceptionif buffer is NULL.
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setInput ( const std::vector< unsigned char > &  buffer,
int  offset,
int  length 
)

Sets input data for compression.

This should be called whenever needsInput() returns true indicating that more input data is required.

Parameters
bufferThe Buffer to read in for compression.
offsetThe position in the Buffer to start reading from.
lengthThe number of bytes to read from the input buffer.
Exceptions
IndexOutOfBoundsExceptionif the offset + length > size of the buffer.
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setInput ( const std::vector< unsigned char > &  buffer)

Sets input data for compression.

This should be called whenever needsInput() returns true indicating that more input data is required.

Parameters
bufferThe Buffer to read in for compression.
Exceptions
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setLevel ( int  level)

Sets the compression level to the specified value.

Parameters
levelThe new Compression level to use.
Exceptions
IllegalArgumentExceptionif the level value is invalid.
IllegalStateExceptionif in the end state.
void decaf::util::zip::Deflater::setStrategy ( int  strategy)

Sets the compression strategy to the specified value.

Parameters
strategyThe new Compression strategy to use.
Exceptions
IllegalArgumentExceptionif the strategy value is invalid.
IllegalStateExceptionif in the end state.

Field Documentation

const int decaf::util::zip::Deflater::BEST_COMPRESSION
static

Compression level for best compression.

const int decaf::util::zip::Deflater::BEST_SPEED
static

Compression level for fastest compression.

const int decaf::util::zip::Deflater::DEFAULT_COMPRESSION
static

Default compression level.

const int decaf::util::zip::Deflater::DEFAULT_STRATEGY
static

Default compression strategy.

const int decaf::util::zip::Deflater::DEFLATED
static

Compression method for the deflate algorithm (the only one currently supported).

const int decaf::util::zip::Deflater::FILTERED
static

Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.

Forces more Huffman coding and less string matching.

const int decaf::util::zip::Deflater::HUFFMAN_ONLY
static

Compression strategy for Huffman coding only.

const int decaf::util::zip::Deflater::NO_COMPRESSION
static

Compression level for no compression.


The documentation for this class was generated from the following file: