Classe Java.util.zip.DeflaterOutputStream em Java

Classe Java.util.zip.DeflaterInputStream em Java Esta classe implementa um filtro de fluxo de saída para compactar dados no formato de compactação 'deflate'. Também é usado como base para outros tipos de filtros de compactação, como GZIPOutputStream. Construtores e Descrição
    DeflaterOutputStream(Saída OutputStream): Cria um novo fluxo de saída com um compressor e tamanho de buffer padrão. DeflaterOutputStream(OutputStream out boolean syncFlush): Cria um novo fluxo de saída com um compressor padrão, um tamanho de buffer padrão e o modo de liberação especificado. DeflaterOutputStream(OutputStream out Deflater def): Cria um novo fluxo de saída com o compressor especificado e um tamanho de buffer padrão. DeflaterOutputStream(OutputStream out Deflater def boolean syncFlush): Cria um novo fluxo de saída com o modo de liberação do compressor especificado e um tamanho de buffer padrão. DeflaterOutputStream (OutputStream out Deflater def int size): Cria um novo fluxo de saída com o compressor e o tamanho do buffer especificados. DeflaterOutputStream (OutputStream out Deflater def int size boolean syncFlush): Cria um novo fluxo de saída com o tamanho do buffer do compressor e o modo de liberação especificados.
Métodos:
    void fechar(): 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 
    vazio protegido deflate(): Writes next block of compressed data to the output stream.
      Syntax :  protected void deflate() throws IOException   Throws:   IOException 
    acabamento vazio(): Finishes writing compressed data to the output stream without closing the underlying stream.
      Syntax :  public void finish() throws IOException   Throws:   IOException 
    void flush() : 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 escrever (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  ();      }   }   
Observação: A saída do programa não será visível no IDE online, pois o arquivo2.txt não pode ser lido aqui. Criar questionário