logo

Classe Java.util.zip.DeflaterOutputStream in Java

Classe Java.util.zip.DeflaterInputStream in Java Questa classe implementa un filtro del flusso di output per comprimere i dati nel formato di compressione "deflate". Viene utilizzato anche come base per altri tipi di filtri di compressione come GZIPOutputStream. Costruttori e descrizione
    DeflaterOutputStream(OutputStream out):Crea un nuovo flusso di output con un compressore e una dimensione del buffer predefiniti. DeflaterOutputStream(OutputStream out booleano syncFlush) :Crea un nuovo flusso di output con un compressore predefinito, una dimensione del buffer predefinita e la modalità di svuotamento specificata. DeflaterOutputStream(OutputStream out Deflater def) :Crea un nuovo flusso di output con il compressore specificato e una dimensione del buffer predefinita. DeflaterOutputStream(OutputStream out Deflater def boolean syncFlush) :Crea un nuovo flusso di output con la modalità di svuotamento del compressore specificata e una dimensione del buffer predefinita. DeflaterOutputStream(OutputStream out Deflater def int size) :Crea un nuovo flusso di output con il compressore e la dimensione del buffer specificati. DeflaterOutputStream(OutputStream out Deflater def int size boolean syncFlush) :Crea un nuovo flusso di output con la dimensione del buffer del compressore e la modalità flush specificate.
Metodi:
    vuoto vicino() : Writes remaining compressed data to the output stream and closes the underlying stream.
      Syntax :  public void close() throws IOException   Overrides:   close in class FilterOutputStream   Throws:   IOException
    sgonfiaggio vuoto protetto() : Writes next block of compressed data to the output stream.
      Syntax :  protected void deflate() throws IOException   Throws:   IOException
    finitura vuota() : Finishes writing compressed data to the output stream without closing the underlying stream.
      Syntax :  public void finish() throws IOException   Throws:   IOException
    svuotamento vuoto() : Flushes the compressed output stream.
      Syntax :  public void flush() throws IOException   Overrides:   flush in class FilterOutputStream   Throws:   IOException
    void write(byte[] b int off int len) : Writes an array of bytes to the compressed output stream.
      Syntax :  public void write(byte[] b int off int len) throws IOException   Overrides:   write in class FilterOutputStream   Parameters:   b - the data to be written off - the start offset of the data len - the length of the data   Throws:   IOException
    void write(int b): Writes a byte to the compressed output stream.
      Syntax :  public void write(int b) throws IOException   Overrides:   write in class FilterOutputStream   Parameters:   b - the byte to be written   Throws:   IOException
Java
//Java program to demonstrate DeflaterOutputStream import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.DeflaterOutputStream; class DeflaterOutputStreamDemo {  public static void main(String[] args) throws IOException   {  FileOutputStream fos = new FileOutputStream('file2.txt');  //Assign FileOutputStream to DeflaterOutputStream  DeflaterOutputStream dos = new DeflaterOutputStream(fos);  //write it into DeflaterOutputStream  for (int i = 0; i <10 ; i++)   {  dos.write(i);  }    //illustrating flush() method()  dos.flush();    //illustrating finish()  //Finishes writing compressed data to the output stream  // without closing the underlying stream  dos.finish();    //fos is not closed  //writing some data on file  fos.write('G');    //Writes remaining compressed data to the output stream  // closes the underlying stream.  dos.close();  } } 
Nota: L'output del programma non sarà visibile sull'IDE online poiché il file2.txt non può essere letto qui. Crea quiz