Java Doc for Deflater.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » zip » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util.zip 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.util.zip.Deflater

Deflater
public class Deflater (Code)
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.

 try {
 // 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");
 } catch(java.io.UnsupportedEncodingException ex) {
 // handle
 } catch (java.util.zip.DataFormatException ex) {
 // handle
 }
 

See Also:   Inflater
version:
   1.51, 05/05/07
author:
   David Connelly


Field Summary
final public static  intBEST_COMPRESSION
     Compression level for best compression.
final public static  intBEST_SPEED
     Compression level for fastest compression.
final public static  intDEFAULT_COMPRESSION
     Default compression level.
final public static  intDEFAULT_STRATEGY
     Default compression strategy.
final public static  intDEFLATED
     Compression method for the deflate algorithm (the only one currently supported).
final public static  intFILTERED
     Compression strategy best used for data consisting mostly of small values with a somewhat random distribution.
final public static  intHUFFMAN_ONLY
     Compression strategy for Huffman coding only.
final public static  intNO_COMPRESSION
     Compression level for no compression.

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

Method Summary
public synchronized  intdeflate(byte[] b, int off, int len)
     Fills specified buffer with compressed data.
public  intdeflate(byte[] b)
     Fills specified buffer with compressed data.
public synchronized  voidend()
     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.
protected  voidfinalize()
     Closes the compressor when garbage is collected.
public synchronized  voidfinish()
     When called, indicates that compression should end with the current contents of the input buffer.
public synchronized  booleanfinished()
     Returns true if the end of the compressed data output stream has been reached.
public synchronized  intgetAdler()
     Returns the ADLER-32 value of the uncompressed data.
public synchronized  longgetBytesRead()
    
public synchronized  longgetBytesWritten()
    
public  intgetTotalIn()
     Returns the total number of uncompressed bytes input so far.
public  intgetTotalOut()
     Returns the total number of compressed bytes output so far.
public  booleanneedsInput()
     Returns true if the input data buffer is empty and setInput() should be called in order to provide more input.
public synchronized  voidreset()
     Resets deflater so that a new set of input data can be processed.
public synchronized  voidsetDictionary(byte[] b, int off, int len)
     Sets preset dictionary for compression.
public  voidsetDictionary(byte[] b)
     Sets preset dictionary for compression.
public synchronized  voidsetInput(byte[] b, int off, int len)
     Sets input data for compression.
public  voidsetInput(byte[] b)
     Sets input data for compression.
public synchronized  voidsetLevel(int level)
     Sets the current compression level to the specified value.
public synchronized  voidsetStrategy(int strategy)
     Sets the compression strategy to the specified value.

Field Detail
BEST_COMPRESSION
final public static int BEST_COMPRESSION(Code)
Compression level for best compression.



BEST_SPEED
final public static int BEST_SPEED(Code)
Compression level for fastest compression.



DEFAULT_COMPRESSION
final public static int DEFAULT_COMPRESSION(Code)
Default compression level.



DEFAULT_STRATEGY
final public static int DEFAULT_STRATEGY(Code)
Default compression strategy.



DEFLATED
final public static int DEFLATED(Code)
Compression method for the deflate algorithm (the only one currently supported).



FILTERED
final public static int FILTERED(Code)
Compression strategy best used for data consisting mostly of small values with a somewhat random distribution. Forces more Huffman coding and less string matching.



HUFFMAN_ONLY
final public static int HUFFMAN_ONLY(Code)
Compression strategy for Huffman coding only.



NO_COMPRESSION
final public static int NO_COMPRESSION(Code)
Compression level for no compression.




Constructor Detail
Deflater
public Deflater(int level, boolean nowrap)(Code)
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)
Parameters:
  nowrap - if true then use GZIP compatible compression



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



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




Method Detail
deflate
public synchronized int deflate(byte[] b, int off, int len)(Code)
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
Parameters:
  off - the start offset of the data
Parameters:
  len - the maximum number of bytes of compressed data the actual number of bytes of compressed data



deflate
public int deflate(byte[] b)(Code)
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 the actual number of bytes of compressed data



end
public synchronized void end()(Code)
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.



finalize
protected void finalize()(Code)
Closes the compressor when garbage is collected.



finish
public synchronized void finish()(Code)
When called, indicates that compression should end with the current contents of the input buffer.



finished
public synchronized boolean finished()(Code)
Returns true if the end of the compressed data output stream has been reached. true if the end of the compressed data output stream hasbeen reached



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



getBytesRead
public synchronized long getBytesRead()(Code)
Returns the total number of uncompressed bytes input so far.

the total (non-negative) number of uncompressed bytes input so far
since:
   1.5



getBytesWritten
public synchronized long getBytesWritten()(Code)
Returns the total number of compressed bytes output so far.

the total (non-negative) number of compressed bytes output so far
since:
   1.5



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

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

the total number of uncompressed bytes input so far



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

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

the total number of compressed bytes output so far



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



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



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



setDictionary
public void setDictionary(byte[] b)(Code)
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
See Also:   Inflater.getAdler



setInput
public synchronized void setInput(byte[] b, int off, int len)(Code)
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
Parameters:
  off - the start offset of the data
Parameters:
  len - the length of the data
See Also:   Deflater.needsInput



setInput
public void setInput(byte[] b)(Code)
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:   Deflater.needsInput



setLevel
public synchronized void setLevel(int level)(Code)
Sets the current compression level to the specified value.
Parameters:
  level - the new compression level (0-9)
exception:
  IllegalArgumentException - if the compression level is invalid



setStrategy
public synchronized void setStrategy(int strategy)(Code)
Sets the compression strategy to the specified value.
Parameters:
  strategy - the new compression strategy
exception:
  IllegalArgumentException - if the compression strategy isinvalid



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.