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.
|
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 |
( |
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. |
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 |
( |
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. |
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 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::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 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::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::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 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::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
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: