java.lang.Objectjava.util.zip.Deflater
public class Deflater
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 byte[] input = inputString.getBytes("UTF-8"); // Compress the bytes byte[] output = new byte[100]; compresser.setInput(input); compresser.finish(); int compressedDataLength = compresser.deflate(output); // Decompress the bytes decompresser.setInput(output, 0, compressedDataLength); byte[] result = new byte[100]; int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String
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, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFLATED
public static final int NO_COMPRESSION
public static final int BEST_SPEED
public static final int BEST_COMPRESSION
public static final int DEFAULT_COMPRESSION
public static final int FILTERED
public static final int HUFFMAN_ONLY
public static final int DEFAULT_STRATEGY
| Constructor Detail |
|---|
public Deflater(int level,
boolean nowrap)
level - the compression level (0-9)nowrap - if true then use GZIP compatible compressionpublic Deflater(int level)
level - the compression level (0-9)public Deflater()
| Method Detail |
|---|
public void setInput(byte[] b,
int off,
int len)
b - the input data bytesoff - the start offset of the datalen - the length of the dataneedsInput()public void setInput(byte[] b)
b - the input data bytesneedsInput()
public void setDictionary(byte[] b,
int off,
int len)
b - the dictionary data bytesoff - the start offset of the datalen - the length of the dataInflater.inflate(byte[], int, int),
Inflater.getAdler()public void setDictionary(byte[] b)
b - the dictionary data bytesInflater.inflate(byte[], int, int),
Inflater.getAdler()public void setStrategy(int strategy)
strategy - the new compression strategy
IllegalArgumentException - if the compression strategy is
invalidpublic void setLevel(int level)
level - the new compression level (0-9)
IllegalArgumentException - if the compression level is invalidpublic boolean needsInput()
public void finish()
public boolean finished()
public int deflate(byte[] b,
int off,
int len)
b - the buffer for the compressed dataoff - the start offset of the datalen - the maximum number of bytes of compressed data
public int deflate(byte[] b)
b - the buffer for the compressed data
public int getAdler()
public int getTotalIn()
Since the number of bytes may be greater than
Integer.MAX_VALUE, the getBytesRead() method is now
the preferred means of obtaining this information.
public long getBytesRead()
public int getTotalOut()
Since the number of bytes may be greater than
Integer.MAX_VALUE, the getBytesWritten() method is now
the preferred means of obtaining this information.
public long getBytesWritten()
public void reset()
public void end()
protected void finalize()
Ces informations proviennent du site de http://java.sun.com
Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :
Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.
Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.
Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.
Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.
Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
7 mots clés dont 0 définis manuellement (plus d'information...).
Avertissement
Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)