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:
level The compression level to use (0-9).
nowrap If 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 ( 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:
buffer The Buffer to write the compressed data to.
Returns:
the actual number of bytes of compressed data.
Exceptions:
IllegalStateException if 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:
buffer The Buffer to write the compressed data to.
offset The position in the Buffer to start writing at.
length The maximum number of byte of data to write.
Returns:
the actual number of bytes of compressed data.
Exceptions:
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if in the end state.
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:
buffer The Buffer to write the compressed data to.
size The size of the passed buffer.
offset The position in the Buffer to start writing at.
length The maximum number of byte of data to write.
Returns:
the actual number of bytes of compressed data.
Exceptions:
NullPointerException if buffer is NULL.
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if 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:
IllegalStateException if in the end state.
long long decaf::util::zip::Deflater::getBytesRead (  )  const
Returns:
the total number of uncompressed bytes input so far.
Exceptions:
IllegalStateException if in the end state.
long long decaf::util::zip::Deflater::getBytesWritten (  )  const
Returns:
the total number of compressed bytes output so far.
Exceptions:
IllegalStateException if 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:
IllegalStateException if 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:
buffer The buffer containing the preset dictionary.
Exceptions:
IllegalStateException if 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:
buffer The buffer containing the preset dictionary.
offset The position in the Buffer to start reading from.
length The number of bytes to read from the input buffer.
Exceptions:
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if 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:
buffer The buffer containing the preset dictionary.
size The size of the passed dictionary buffer.
offset The position in the Buffer to start reading from.
length The number of bytes to read from the input buffer.
Exceptions:
NullPointerException if buffer is NULL.
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if 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:
buffer The Buffer to read in for compression.
Exceptions:
IllegalStateException if 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:
buffer The Buffer to read in for compression.
offset The position in the Buffer to start reading from.
length The number of bytes to read from the input buffer.
Exceptions:
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if 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:
buffer The Buffer to read in for compression.
size The size in bytes of the buffer passed.
offset The position in the Buffer to start reading from.
length The number of bytes to read from the input buffer.
Exceptions:
NullPointerException if buffer is NULL.
IndexOutOfBoundsException if the offset + length > size of the buffer.
IllegalStateException if in the end state.
void decaf::util::zip::Deflater::setLevel ( int  level  ) 

Sets the compression level to the specified value.

Parameters:
level The new Compression level to use.
Exceptions:
IllegalArgumentException if the level value is invalid.
IllegalStateException if in the end state.
void decaf::util::zip::Deflater::setStrategy ( int  strategy  ) 

Sets the compression strategy to the specified value.

Parameters:
strategy The new Compression strategy to use.
Exceptions:
IllegalArgumentException if the strategy value is invalid.
IllegalStateException if in the end state.

Field Documentation

Compression level for best compression.

Compression level for fastest compression.

Default compression level.

Default compression strategy.

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

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

Forces more Huffman coding and less string matching.

Compression strategy for Huffman coding only.

Compression level for no compression.


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

Generated on 1 Dec 2014 for activemq-cpp-3.8.2 by  doxygen 1.6.1