java.util.zip

Class Deflater


public class Deflater
extends Object

This class provides support for general purpose compression using the popular ZLIB compression library. The ZLIB compression library was initially developed as part of the PNG graphics standard and is not protected by patents. It is fully described in the specifications at the java.util.zip package description.

The following code fragment demonstrates a trivial compression and decompression of a string using Deflater and Inflater.

 // Encode a String into bytes
 String inputString = "blahblahblah\u20AC\u20AC";
 byte[] input = inputString.getBytes("UTF-8");

 // Compress the bytes
 byte[] output = new byte[100];
 Deflater compresser = new Deflater();
 compresser.setInput(input);
 compresser.finish();
 int compressedDataLength = compresser.deflate(output);

 // Decompress the bytes
 Inflater decompresser = new Inflater();
 decompresser.setInput(output, 0, compressedDataLength);
 byte[] result = new byte[100];
 int resultLength = decompresser.inflate(result);
 decompresser.end();

 // Decode the bytes into a String
 String outputString = new String(result, 0, resultLength, "UTF-8");
 
See Also:
Inflater

Field Summary

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

Constructor Summary

Deflater()
Creates a new compressor with the default compression level.
Deflater(int level)
Creates a new compressor using the specified compression level.
Deflater(int level, boolean nowrap)
Creates a new compressor using the specified compression level.

Method Summary

int
deflate(byte[] b)
Fills specified buffer with compressed data.
int
deflate(byte[] b, int off, int len)
Fills specified buffer with compressed data.
void
end()
Closes the compressor and discards any unprocessed input.
protected void
finalize()
Closes the compressor when garbage is collected.
void
finish()
When called, indicates that compression should end with the current contents of the input buffer.
boolean
finished()
Returns true if the end of the compressed data output stream has been reached.
int
getAdler()
Returns the ADLER-32 value of the uncompressed data.
long
getBytesRead()
Returns the total number of uncompressed bytes input so far.
long
getBytesWritten()
Returns the total number of compressed bytes output so far.
int
getTotalIn()
Returns the total number of uncompressed bytes input so far.
int
getTotalOut()
Returns the total number of compressed bytes output so far.
boolean
needsInput()
Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
void
reset()
Resets deflater so that a new set of input data can be processed.
void
setDictionary(byte[] b)
Sets preset dictionary for compression.
void
setDictionary(byte[] b, int off, int len)
Sets preset dictionary for compression.
void
setInput(byte[] b)
Sets input data for compression.
void
setInput(byte[] b, int off, int len)
Sets input data for compression.
void
setLevel(int level)
Sets the current compression level to the specified value.
void
setStrategy(int strategy)
Sets the compression strategy to the specified value.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

BEST_COMPRESSION

public static final int BEST_COMPRESSION
Compression level for best compression.
Field Value:
9
Usages and Demos :

View More Examples of Deflater.BEST_COMPRESSION
   1:             try {
   2:                 ZipHelper.fileToZip(getTempPath(), backupFile, Deflater.BEST_COMPRESSION);
   3:             } catch (Throwable e) {
   4:                 throw new Exception("Error zipping backup files into " + backupFile.getAbsolutePath(), e);
   5:             }

View Full Code Here
   1:         JarOutputStream stream = new JarOutputStream(fileOutputStream, manifest);
   2:         stream.setLevel(Deflater.BEST_COMPRESSION);
   3:         for (JarFileEntry entry : entries.values()) {
   4:             if (entry == manifestEntry) continue;
   5:             stream.putNextEntry(new ZipEntry(entry.getName()));

View Full Code Here
   1:       Deflater compressor = new Deflater();
   2:       compressor.setLevel(Deflater.BEST_COMPRESSION);
   3: 
   4:       compressor.setInput(input);
   5:       compressor.finish();

View Full Code Here
   1:         zip.setMethod(ZipOutputStream.DEFLATED);
   2:         zip.setLevel(Deflater.BEST_COMPRESSION);
   3:         zip.setComment("compiere");
   4:         byte[] deflatedData = null;
   5:         try

View Full Code Here
   1:             zip.setMethod(ZipOutputStream.DEFLATED);
   2:             zip.setLevel(Deflater.BEST_COMPRESSION);
   3:             zip.setComment(readme);
   4:                             
   5:             ZipEntry entry = new ZipEntry("readme.txt");

View Full Code Here

BEST_SPEED

public static final int BEST_SPEED
Compression level for fastest compression.
Field Value:
1
Usages and Demos :

View More Examples of Deflater.BEST_SPEED
   1:                                    new File(System.getProperty("user.home")),
   2:                                    Deflater.BEST_SPEED);
   3:     }
   4: 

View Full Code Here
   1:       ZipOutputStream zipStream = new ZipOutputStream(byteStream);
   2:       zipStream.setLevel(Deflater.BEST_SPEED);
   3:       
   4:       try
   5:       {

View Full Code Here

DEFAULT_COMPRESSION

public static final int DEFAULT_COMPRESSION
Default compression level.
Field Value:
-1
Usages and Demos :

View More Examples of Deflater.DEFAULT_COMPRESSION
   1:   {
   2:     this(out, Deflater.DEFAULT_COMPRESSION, Deflater.DEFAULT_STRATEGY);
   3:   }
   4: 
   5:   public void write(int v)

View Full Code Here
   1:     this(os,
   2:      Deflater.DEFAULT_COMPRESSION,
   3:      Deflater.DEFAULT_STRATEGY,
   4:      ZlibModule.FORCE_GZIP);
   5:   }

View Full Code Here
   1:                     } else if(sync == 1) {
   2:                         deflater.setLevel(Deflater.DEFAULT_COMPRESSION);
   3:                         sync = 2;
   4:                         continue;
   5:                     }

View Full Code Here
   1:                     } else if(sync == 1) {
   2:                         deflater.setLevel(Deflater.DEFAULT_COMPRESSION);
   3:                         sync = 2;
   4:                         continue;
   5:                     }

View Full Code Here
   1:     }
   2:     return Deflater.DEFAULT_COMPRESSION;
   3:   }
   4: 
   5:   private int getCompressionStrategy(String input)

View Full Code Here

DEFAULT_STRATEGY

public static final int DEFAULT_STRATEGY
Default compression strategy.
Field Value:
0
Usages and Demos :

View More Examples of Deflater.DEFAULT_STRATEGY
   1:   {
   2:     this(out, Deflater.DEFAULT_COMPRESSION, Deflater.DEFAULT_STRATEGY);
   3:   }
   4: 
   5:   public void write(int v)

View Full Code Here
   1:      Deflater.DEFAULT_COMPRESSION,
   2:      Deflater.DEFAULT_STRATEGY,
   3:      ZlibModule.FORCE_GZIP);
   4:   }

View Full Code Here
   1:     }
   2:     return Deflater.DEFAULT_STRATEGY;
   3:   }
   4: 
   5:   public String toString()

View Full Code Here
   1:       gzOut = new ZlibOutputStream(out, level,
   2:                    Deflater.DEFAULT_STRATEGY,
   3:                    encodingMode);
   4:         ...
   5:     
   6:     return Deflater.DEFAULT_STRATEGY;
   7:   }
   8: }

View Full Code Here

DEFLATED

public static final int DEFLATED
Compression method for the deflate algorithm (the only one currently supported).
Field Value:
8

FILTERED

public static final int FILTERED
Compression strategy best used for data consisting mostly of small values with a somewhat random distribution. Forces more Huffman coding and less string matching.
Field Value:
1
Usages and Demos :

View More Examples of Deflater.FILTERED
   1:       case 'f':
   2:         return Deflater.FILTERED;
   3:       case 'h':
   4:         return Deflater.HUFFMAN_ONLY;
   5:       }

View Full Code Here
   1:       case 'f':
   2:         return Deflater.FILTERED;
   3:     
   4:       case 'h':
   5:         return Deflater.HUFFMAN_ONLY;

View Full Code Here

HUFFMAN_ONLY

public static final int HUFFMAN_ONLY
Compression strategy for Huffman coding only.
Field Value:
2
Usages and Demos :

View More Examples of Deflater.HUFFMAN_ONLY
   1:       case 'h':
   2:         return Deflater.HUFFMAN_ONLY;
   3:       }
   4:     }
   5:     return Deflater.DEFAULT_STRATEGY;

View Full Code Here
   1:       case 'h':
   2:         return Deflater.HUFFMAN_ONLY;
   3:       }
   4:     }
   5:     

View Full Code Here

NO_COMPRESSION

public static final int NO_COMPRESSION
Compression level for no compression.
Field Value:
0
Usages and Demos :

View More Examples of Deflater.NO_COMPRESSION
   1:                         deflater.setInput(EMPTY);
   2:                         deflater.setLevel(Deflater.NO_COMPRESSION);
   3:                         sync = 1;
   4:                         continue;
   5:                     } else if(sync == 1) {

View Full Code Here
   1:                         deflater.setInput(EMPTY);
   2:                         deflater.setLevel(Deflater.NO_COMPRESSION);
   3:                         sync = 1;
   4:                         continue;
   5:                     } else if(sync == 1) {

View Full Code Here
   1: 
   2:         zos.setLevel(Deflater.NO_COMPRESSION);
   3: 
   4:         ZipEntry ze = new ZipEntry(java.net.URLEncoder.encode(path, "UTF-8"));
   5:         ze.setExtra(uid.getBytes("UTF-8"));

View Full Code Here

Constructor Details

Deflater

public Deflater()
Creates a new compressor with the default compression level. Compressed data will be generated in ZLIB format.
Usages and Demos :

View More Examples of Deflater()
   1:     byte[] outData = new byte[ profData.length * 2 ];
   2:     Deflater deflater = new Deflater();
   3:     deflater.setInput( profData );
   4:     deflater.finish();
   5:     int n = deflater.deflate( outData );

View Full Code Here
   1:     if (flow == Direction.FORWARD)
   2:       compressor = new Deflater();
   3:     else
   4:       decompressor = new Inflater();
   5:   }

View Full Code Here
   1:     
   2:     private Deflater DEFLATER = new Deflater();
   3:     private WriteBufferChannel SINK = new WriteBufferChannel(1024 * 1024);
   4:     private DeflaterWriter WRITER = new DeflaterWriter(DEFLATER, SINK);
   5:     private static Random RND = new Random();

View Full Code Here
   1: 
   2:       Deflater compressor = new Deflater();
   3:       compressor.setLevel(Deflater.BEST_COMPRESSION);
   4: 
   5:       compressor.setInput(input);

View Full Code Here

Deflater

public Deflater(int level)
Creates a new compressor using the specified compression level. Compressed data will be generated in ZLIB format.
Parameters:
level - the compression level (0-9)
Usages and Demos :

View More Examples of Deflater(int level)
   1:     super(out);
   2:     compressor = new Deflater(Deflater.BEST_SPEED);
   3:   }
   4: 
   5:   public void write(int x)

View Full Code Here
   1:    {
   2:       Deflater deflater = new Deflater(compressionLevel);
   3:       deflater.setInput(input, 0, input.length);
   4:       deflater.finish();
   5:       byte[] buff = new byte[input.length + 50];

View Full Code Here
   1:     static public byte[] compress(byte[] input, int compressionLevel) {
   2:         Deflater deflater = new Deflater(compressionLevel);
   3:         deflater.setInput(input, 0, input.length);
   4:         deflater.finish();
   5:         byte[] buff = new byte[input.length + 50];

View Full Code Here
   1:         writeIndex=0;
   2:         deflater=new Deflater(Deflater.BEST_COMPRESSION);
   3:     }
   4: 
   5:     public synchronized void write(byte[] b) throws IOException {

View Full Code Here
   1: 
   2:         java.util.zip.Deflater deflater = new java.util.zip.Deflater(compressionLevel);
   3:         deflater.setInput (input, 0, input.length);
   4:         deflater.finish ();
   5:         byte[] buff = new byte[input.length + 50];

View Full Code Here

Deflater

public Deflater(int level,
                boolean nowrap)
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 (0-9)
nowrap - if true then use GZIP compatible compression
Usages and Demos :

View More Examples of Deflater(int level,boolean nowrap)
   1:     private DefOutputStream(final OutputStream out, final int size)
   2:         { super(out, new Deflater(Deflater.BEST_COMPRESSION, true), size); }
   3: 
   4:     public DefOutputStream(final OutputStream out)
   5:         { this(out, 512); }

View Full Code Here
   1:       {
   2:          _deflater = new Deflater(oge - MUSCLE_MESSAGE_DEFAULT_ENCODING, false);
   3:          _baos = new ByteArrayOutputStream(flatSize);
   4:         ...
   5:       {
   6:          _deflater = new Deflater(oge - MUSCLE_MESSAGE_DEFAULT_ENCODING, false);
   7:          _baos = new ByteArrayOutputStream(flatSize);
   8:          _dos = new LEDataOutputStream(new DeflaterStreamResetHack(_baos, _deflater, oge - MUSCLE_MESSAGE_DEFAULT_ENCODING));
   9:          independent = true;

View Full Code Here
   1:     if (encodingMode == ZlibModule.FORCE_GZIP)
   2:       defl = new Deflater(compressionLevel, true);
   3:     else
   4:         ...
   5:       defl = new Deflater(compressionLevel, false);
   6: 
   7:     defl.setStrategy(strategy);

View Full Code Here
   1:     if (encodingMode == ZlibModule.FORCE_GZIP)
   2:       def = new Deflater(compressionLevel, true);
   3:     else
   4:         ...
   5:       def = new Deflater(compressionLevel, false);
   6: 
   7:     def.setStrategy(strategy);

View Full Code Here
   1:     public ResettableGZIPOutputStream(OutputStream o) {
   2:         super(o, new Deflater(9, true));
   3:         _headerWritten = false;
   4:         _crc32 = new CRC32();
   5:     }

View Full Code Here

Method Details

deflate

public int deflate(byte[] b)
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:
b - the buffer for the compressed data
Returns:
the actual number of bytes of compressed data
Usages and Demos :

View More Examples of deflate(byte[] b)
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:    {
   6:       Deflater deflater = new Deflater(compressionLevel);
   7:       deflater.setInput(input, 0, input.length);
   8:         ...
   9:       byte[] buff = new byte[input.length + 50];
  10:       int wsize = deflater.deflate(buff);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     static public byte[] compress(byte[] input, int compressionLevel) {
   6:         Deflater deflater = new Deflater(compressionLevel);
   7:         deflater.setInput(input, 0, input.length);
   8:         ...
   9:         byte[] buff = new byte[input.length + 50];
  10:         int wsize = deflater.deflate(buff);

View Full Code Here
   1: import java.util.zip.InflaterInputStream;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] outData = new byte[ profData.length * 2 ];
   6:     Deflater deflater = new Deflater();
   7:     deflater.setInput( profData );
   8:         ...
   9:     deflater.finish();
  10:     int n = deflater.deflate( outData );
  11:     data = new byte[ n + 11 + 2 ];

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: {
   6:   private Deflater compressor;
   7: 
   8:         ...
   9:     if (flow == Direction.FORWARD)
  10:       compressor = new Deflater();
  11:     else
  12:         ...
  13:   {
  14:     int len = compressor.deflate(zlibBuffer);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: public class COMPRESS extends Protocol {
   6:     Deflater[] deflater_pool=null;
   7:     Inflater[] inflater_pool=null;
   8:         ...
   9:                 int tmp_index=getDeflaterIndex();
  10:                 synchronized(deflater) {
  11:                     deflater.reset();
  12:         ...
  13:                     deflater.finish();
  14:                     deflater.deflate(compressed_payload);

View Full Code Here

deflate

public int deflate(byte[] b,
                   int off,
                   int len)
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:
b - the buffer for the compressed data
off - the start offset of the data
len - the maximum number of bytes of compressed data
Returns:
the actual number of bytes of compressed data
Usages and Demos :

View More Examples of deflate(byte[] b,int off,int len)
   1: {
   2:   Deflater compressor;
   3: 
   4:         ...
   5:     super(out);
   6:     compressor = new Deflater(Deflater.BEST_SPEED);
   7:   }
   8:         ...
   9:   {
  10:     int newlen = compressor.deflate(b, off, len);
  11:     out.write(len);

View Full Code Here
   1: import java.util.zip.Inflater;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5: 
   6:   public void deflateToChunk( Deflater def ) 
   7:   {
   8:         ...
   9:     offset += def.deflate( data, offset, data.length - offset );
  10:   }

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] packed = new byte[1024 * 64];
   6:     Deflater def = new Deflater(Deflater.BEST_SPEED);
   7:     byte count;
   8:         ...
   9:             def.finish();
  10:             packedSize = def.deflate(packed, 1, packed.length - 1);

View Full Code Here
   1: import java.util.zip.Adler32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     try {
   6:       Deflater deflater = new Deflater(level, true);
   7:       Adler32 crc = new Adler32();
   8:         ...
   9: 
  10:         while ((len = deflater.deflate(buffer, 0, buffer.length)) > 0) {
  11:           out.append(buffer, 0, len);
  12:         ...
  13: 
  14:         while ((len = deflater.deflate(buffer, 0, buffer.length)) > 0) {

View Full Code Here
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.ZipException;
   4:         ...
   5: 
   6:     public static final int DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION;
   7: 
   8:         ...
   9: 
  10:     protected Deflater def = new Deflater(level, true);
  11: 
  12:         ...
  13:     protected final void deflate() throws IOException {
  14:         int len = def.deflate(buf, 0, buf.length);

View Full Code Here

end

public void 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 finalize() method. Once this method is called, the behavior of the Deflater object is undefined.
Usages and Demos :

View More Examples of end()
   1: import java.lang.reflect.UndeclaredThrowableException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.DeflaterOutputStream;
   4:         ...
   5:     {
   6:         Deflater deflater = new Deflater(level);
   7:         try
   8:         ...
   9:         {
  10:             deflater.end();
  11:         }

View Full Code Here
   1: import java.util.Random;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     
   6:     private Deflater DEFLATER = new Deflater();
   7:     private WriteBufferChannel SINK = new WriteBufferChannel(1024 * 1024);
   8:         ...
   9:     public void tearDown() {
  10:         DEFLATER.end();
  11:         ...
  12:         INFLATER.end();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5: 
   6:       Deflater compressor = new Deflater();
   7:       compressor.setLevel(Deflater.BEST_COMPRESSION);
   8:         ...
   9:       
  10:       compressor.end();

View Full Code Here
   1: import java.util.Random;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.DeflaterOutputStream;
   4:         ...
   5:         OutputStream dos = null;
   6:         Deflater def = new Deflater();
   7:         try {
   8:         ...
   9:             try { dos.close(); } catch(IOException x) {}
  10:             def.end();
  11:         }

View Full Code Here
   1: import java.util.EnumMap;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.DeflaterOutputStream;
   4:         ...
   5:     
   6:     public static void close(Deflater deflater) {
   7:         if(deflater != null) {
   8:         ...
   9:             deflater.end();
  10:         }
  11:         ...
  12:         if(inflater != null) {
  13:             inflater.end();

View Full Code Here

finalize

protected void finalize()
Closes the compressor when garbage is collected.
Overrides:
finalize in interface Object

finish

public void finish()
When called, indicates that compression should end with the current contents of the input buffer.
Usages and Demos :

View More Examples of finish()
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:    {
   6:       Deflater deflater = new Deflater(compressionLevel);
   7:       deflater.setInput(input, 0, input.length);
   8:         ...
   9:       deflater.finish();
  10:       byte[] buff = new byte[input.length + 50];

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     static public byte[] compress(byte[] input, int compressionLevel) {
   6:         Deflater deflater = new Deflater(compressionLevel);
   7:         deflater.setInput(input, 0, input.length);
   8:         ...
   9:         deflater.finish();
  10:         byte[] buff = new byte[input.length + 50];

View Full Code Here
   1: import java.io.IOException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int writeIndex;
   6:     private Deflater deflater;
   7: 
   8:         ...
   9:             deflater.setInput(buffer, 0, writeIndex);
  10:             deflater.finish();

View Full Code Here
   1: import java.util.zip.InflaterInputStream;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] outData = new byte[ profData.length * 2 ];
   6:     Deflater deflater = new Deflater();
   7:     deflater.setInput( profData );
   8:         ...
   9:     deflater.finish();
  10:     int n = deflater.deflate( outData );

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: {
   6:   private Deflater compressor;
   7: 
   8:         ...
   9:     if (flow == Direction.FORWARD)
  10:       compressor = new Deflater();
  11:     else
  12:         ...
  13:           {
  14:             compressor.finish();

View Full Code Here

finished

public boolean finished()
Returns true if the end of the compressed data output stream has been reached.
Returns:
true if the end of the compressed data output stream has been reached
Usages and Demos :

View More Examples of finished()
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: {
   6:   private Deflater compressor;
   7: 
   8:         ...
   9:     if (flow == Direction.FORWARD)
  10:       compressor = new Deflater();
  11:     else
  12:         ...
  13:       {
  14:         if (! compressor.finished())

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5: 
   6:       Deflater compressor = new Deflater();
   7:       compressor.setLevel(Deflater.BEST_COMPRESSION);
   8:         ...
   9:       byte[] buf = new byte[1024];
  10:       while (!compressor.finished()) {
  11:         int count = compressor.deflate(buf);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:   private final Mac mac;
   6:   private final Deflater deflater;
   7:   private final SessionImpl session;
   8:         ...
   9:         deflater.finish();
  10:         while (!deflater.finished())
  11:           {

View Full Code Here
   1:     private CRC32    crcCounter;
   2:     private Deflater    pixmapDeflater;
   3:     private long    idatChunkSizeOffset;
   4:         ...
   5:         pixmapDeflater.finish();
   6:         while ( !pixmapDeflater.finished() ) {
   7:         deflate_size = pixmapDeflater.deflate(deflate_buf);
   8:         ...
   9:     
  10:     pixmapDeflater = new Deflater();
  11:     

View Full Code Here
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.ZipException;
   4:         ...
   5: 
   6:     public static final int DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION;
   7: 
   8:         ...
   9: 
  10:     protected Deflater def = new Deflater(level, true);
  11: 
  12:         ...
  13:             def.finish();
  14:             while (!def.finished()) {

View Full Code Here

getAdler

public int getAdler()
Returns the ADLER-32 value of the uncompressed data.
Returns:
the ADLER-32 value of the uncompressed data

getBytesRead

public long getBytesRead()
Returns the total number of uncompressed bytes input so far.
Returns:
the total (non-negative) number of uncompressed bytes input so far

getBytesWritten

public long getBytesWritten()
Returns the total number of compressed bytes output so far.
Returns:
the total (non-negative) number of compressed bytes output so far

getTotalIn

public int getTotalIn()
Returns the total number of uncompressed bytes input so far.

Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesRead() method is now the preferred means of obtaining this information.

Returns:
the total number of uncompressed bytes input so far
Usages and Demos :

View More Examples of getTotalIn()
   1: 
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: 
   6:     private final Deflater deflater;
   7: 
   8:         ...
   9:         try {
  10:             return deflater.getTotalIn();
  11:         } catch (NullPointerException npe) {
  12:         ...
  13:         try {
  14:             return inflater.getTotalIn();

View Full Code Here
   1: import java.util.Properties;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     
   6:     private Deflater _deflater;
   7:     
   8:         ...
   9:             if(isWriteDeflated()) {
  10:                 _deflater = new Deflater();
  11:                 _out = new CompressingOutputStream(_out, _deflater);
  12:         ...
  13:             if(isReadDeflated()) {
  14:                 pCompressed = _inflater.getTotalIn();

View Full Code Here

getTotalOut

public int getTotalOut()
Returns the total number of compressed bytes output so far.

Since the number of bytes may be greater than Integer.MAX_VALUE, the getBytesWritten() method is now the preferred means of obtaining this information.

Returns:
the total number of compressed bytes output so far
Usages and Demos :

View More Examples of getTotalOut()
   1: 
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: 
   6:     private final Deflater deflater;
   7: 
   8:         ...
   9:         try {
  10:             return deflater.getTotalOut();
  11:         } catch (NullPointerException npe) {
  12:         ...
  13:         try {
  14:             return inflater.getTotalOut();

View Full Code Here
   1: import java.util.Properties;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     
   6:     private Deflater _deflater;
   7:     
   8:         ...
   9:             if(isWriteDeflated()) {
  10:                 _deflater = new Deflater();
  11:                 _out = new CompressingOutputStream(_out, _deflater);
  12:         ...
  13:                 pCompressed = _inflater.getTotalIn();
  14:                 pUncompressed = _inflater.getTotalOut();

View Full Code Here

needsInput

public boolean needsInput()
Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
Returns:
true if the input data buffer is empty and setInput() should be called in order to provide more input
Usages and Demos :

View More Examples of needsInput()
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: {
   6:   private Deflater compressor;
   7: 
   8:         ...
   9:     if (flow == Direction.FORWARD)
  10:       compressor = new Deflater();
  11:     else
  12:         ...
  13:         compressor.setInput(in, offset, length);
  14:         while (! compressor.needsInput())

View Full Code Here
   1: import java.util.zip.Adler32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     try {
   6:       Deflater deflater = new Deflater(level, true);
   7:       Adler32 crc = new Adler32();
   8:         ...
   9:       while (! isFinished) {
  10:         while (! isFinished && deflater.needsInput()) {
  11:           len = data.read(buffer, 0, buffer.length);
  12:         ...
  13:       while (! isFinished) {
  14:         if (! isFinished && deflater.needsInput()) {

View Full Code Here
   1:     private CRC32    crcCounter;
   2:     private Deflater    pixmapDeflater;
   3:     private long    idatChunkSizeOffset;
   4:         ...
   5:         pixmapDeflater.setInput(buf, in_byte_off, (int) Math.min(DEFLATE_INPUT_SIZE, buf.length - in_byte_off));
   6:         while ( !pixmapDeflater.needsInput() ) {
   7:         deflate_size = pixmapDeflater.deflate(deflate_buf);
   8:         ...
   9:     
  10:     pixmapDeflater = new Deflater();
  11:     

View Full Code Here
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.ZipException;
   4:         ...
   5: 
   6:     public static final int DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION;
   7: 
   8:         ...
   9: 
  10:     protected Deflater def = new Deflater(level, true);
  11: 
  12:         ...
  13:                     def.setInput(b, offset, length);
  14:                     while (!def.needsInput()) {

View Full Code Here

reset

public void reset()
Resets deflater so that a new set of input data can be processed. Keeps current compression level and strategy settings.
Usages and Demos :

View More Examples of reset()
   1: import java.io.IOException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int writeIndex;
   6:     private Deflater deflater;
   7: 
   8:         ...
   9:         if (writeIndex >= minCompress) {
  10:             deflater.reset();
  11:             deflater.setInput(buffer, 0, writeIndex);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: public class COMPRESS extends Protocol {
   6:     Deflater[] deflater_pool=null;
   7:     Inflater[] inflater_pool=null;
   8:         ...
   9:                 int tmp_index=getDeflaterIndex();
  10:                 synchronized(deflater) {
  11:         ...
  12:                     deflater.reset();

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] packed = new byte[1024 * 64];
   6:     Deflater def = new Deflater(Deflater.BEST_SPEED);
   7:     byte count;
   8:         ...
   9:         if (size > 100) {
  10:             def.reset();
  11:             def.setInput(unpacked, 1, size);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:   private final Mac mac;
   6:   private final Deflater deflater;
   7:   private final SessionImpl session;
   8:         ...
   9:         fragmentLength = ((int) deflater.getBytesWritten()) + maclen + ivlen;
  10:         deflater.reset();
  11:         offset = 0;

View Full Code Here
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.ZipException;
   4:         ...
   5: 
   6:     public static final int DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION;
   7: 
   8:         ...
   9: 
  10:     protected Deflater def = new Deflater(level, true);
  11: 
  12:         ...
  13:         long realCrc = crc.getValue();
  14:         crc.reset();

View Full Code Here

setDictionary

public void setDictionary(byte[] b)
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:
b - the dictionary data bytes
See Also:
Inflater.inflate, Inflater.getAdler()

setDictionary

public void setDictionary(byte[] b,
                          int off,
                          int len)
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:
b - the dictionary data bytes
off - the start offset of the data
len - the length of the data
See Also:
Inflater.inflate, Inflater.getAdler()

setInput

public void setInput(byte[] b)
Sets input data for compression. This should be called whenever needsInput() returns true indicating that more input data is required.
Parameters:
b - the input data bytes
See Also:
needsInput()
Usages and Demos :

View More Examples of setInput(byte[] b)
   1: import java.util.zip.InflaterInputStream;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] outData = new byte[ profData.length * 2 ];
   6:     Deflater deflater = new Deflater();
   7:         ...
   8:     deflater.setInput( profData );
   9:     deflater.finish();

View Full Code Here
   1: import java.util.Iterator;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5: 
   6:       Deflater compressor = new Deflater();
   7:       compressor.setLevel(Deflater.BEST_COMPRESSION);
   8:         ...
   9: 
  10:       compressor.setInput(input);
  11:       compressor.finish();

View Full Code Here
   1: import java.util.Vector;
   2: import java.util.zip.Deflater;
   3: import java.awt.color.ColorSpace;
   4:         ...
   5: 
   6:     deflater.setInput( data ); 
   7:         ...
   8:     deflater.finish();
   9: 
  10:         ...
  11:     chunk = new PNGData( defaultChunkSize );
  12:     chunk.deflateToChunk( deflater );

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:   {
   6:     Deflater deflater = new Deflater();
   7:         ...
   8:     deflater.setInput( data );
   9:     deflater.finish();

View Full Code Here
   1: import java.nio.channels.Channel;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int sync = 0;
   6:     public DeflaterWriter(Deflater deflater) {
   7:         this(deflater, null);
   8:         ...
   9:                     if(sync == 0) {
  10:                         deflater.setInput(EMPTY);
  11:                         deflater.setLevel(Deflater.NO_COMPRESSION);
  12:         ...
  13:                 try {
  14:                     deflater.setInput(incoming.array(), 0, incoming.position());

View Full Code Here

setInput

public void setInput(byte[] b,
                     int off,
                     int len)
Sets input data for compression. This should be called whenever needsInput() returns true indicating that more input data is required.
Parameters:
b - the input data bytes
off - the start offset of the data
len - the length of the data
See Also:
needsInput()
Usages and Demos :

View More Examples of setInput(byte[] b,int off,int len)
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:    {
   6:       Deflater deflater = new Deflater(compressionLevel);
   7:         ...
   8:       deflater.setInput(input, 0, input.length);
   9:       deflater.finish();
  10:         ...
  11:          Inflater inflater = new Inflater();
  12:          inflater.setInput(input, 4, input.length - 4);

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5:     static public byte[] compress(byte[] input, int compressionLevel) {
   6:         Deflater deflater = new Deflater(compressionLevel);
   7:         ...
   8:         deflater.setInput(input, 0, input.length);
   9:         deflater.finish();
  10:         ...
  11:             Inflater inflater = new Inflater();
  12:             inflater.setInput(input, 4, input.length - 4);

View Full Code Here
   1: import java.io.IOException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int writeIndex;
   6:     private Deflater deflater;
   7: 
   8:         ...
   9:             deflater.reset();
  10:             deflater.setInput(buffer, 0, writeIndex);
  11:             deflater.finish();

View Full Code Here
   1: import java.util.zip.DataFormatException;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.Inflater;
   4:         ...
   5: {
   6:   private Deflater compressor;
   7: 
   8:         ...
   9:     if (flow == Direction.FORWARD)
  10:       compressor = new Deflater();
  11:     else
  12:         ...
  13:       {
  14:         compressor.setInput(in, offset, length);

View Full Code Here
   1: import java.util.ArrayList;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     byte[] packed = new byte[1024 * 64];
   6:     Deflater def = new Deflater(Deflater.BEST_SPEED);
   7:     byte count;
   8:         ...
   9:             def.reset();
  10:             def.setInput(unpacked, 1, size);
  11:             def.finish();

View Full Code Here

setLevel

public void setLevel(int level)
Sets the current compression level to the specified value.
Parameters:
level - the new compression level (0-9)
Throws:
IllegalArgumentException - if the compression level is invalid
Usages and Demos :

View More Examples of setLevel(int level)
   1: import java.util.Iterator;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5: 
   6:       Deflater compressor = new Deflater();
   7:         ...
   8:       compressor.setLevel(Deflater.BEST_COMPRESSION);

View Full Code Here
   1: import java.nio.channels.Channel;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int sync = 0;
   6:     public DeflaterWriter(Deflater deflater) {
   7:         this(deflater, null);
   8:         ...
   9:                         deflater.setInput(EMPTY);
  10:                         deflater.setLevel(Deflater.NO_COMPRESSION);
  11:                         sync = 1;
  12:         ...
  13:                     } else if(sync == 1) {
  14:                         deflater.setLevel(Deflater.DEFAULT_COMPRESSION);

View Full Code Here
   1: import java.io.IOException;
   2: import java.util.zip.Deflater;
   3: 
   4:         ...
   5:     private int sync = 0;
   6:     public DeflaterWriter(Deflater deflater) {
   7:         this(deflater, null);
   8:         ...
   9:                         deflater.setInput(EMPTY);
  10:                         deflater.setLevel(Deflater.NO_COMPRESSION);
  11:                         sync = 1;
  12:         ...
  13:                     } else if(sync == 1) {
  14:                         deflater.setLevel(Deflater.DEFAULT_COMPRESSION);

View Full Code Here
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.ZipException;
   4:         ...
   5: 
   6:     public static final int DEFAULT_COMPRESSION = Deflater.DEFAULT_COMPRESSION;
   7: 
   8:         ...
   9: 
  10:     protected Deflater def = new Deflater(level, true);
  11: 
  12:         ...
  13:         if (entry.getMethod() == DEFLATED && hasCompressionLevelChanged) {
  14:             def.setLevel(level);

View Full Code Here

setStrategy

public void setStrategy(int strategy)
Sets the compression strategy to the specified value.
Parameters:
strategy - the new compression strategy
Throws:
IllegalArgumentException - if the compression strategy is invalid
Usages and Demos :

View More Examples of setStrategy(int strategy)
   1: import java.util.zip.CRC32;
   2: import java.util.zip.Deflater;
   3: import java.util.zip.DeflaterOutputStream;
   4:         ...
   5: 
   6:   private ZlibOutputStream(OutputStream os, Deflater def)
   7:     throws IOException
   8:         ...
   9:     this(os,
  10:      Deflater.DEFAULT_COMPRESSION,
  11:      Deflater.DEFAULT_STRATEGY,
  12:         ...
  13: 
  14:     def.setStrategy(strategy);

View Full Code Here