Java の Java.util.zip.DeflaterOutputStream クラス

Java の Java.util.zip.DeflaterInputStream クラス このクラスは、「deflate」圧縮形式でデータを圧縮するための出力ストリーム フィルターを実装します。これは、GZIPOutputStream などの他のタイプの圧縮フィルターの基礎としても使用されます。 コンストラクターと説明
    DeflaterOutputStream(出力ストリーム出力) : デフォルトのコンプレッサーとバッファー サイズを使用して新しい出力ストリームを作成します。 DeflaterOutputStream(OutputStream out boolean syncFlush) : デフォルトのコンプレッサー、デフォルトのバッファー サイズ、および指定されたフラッシュ モードを使用して、新しい出力ストリームを作成します。 DeflaterOutputStream(OutputStream out デフレーター def) : 指定されたコンプレッサーとデフォルトのバッファー サイズを使用して新しい出力ストリームを作成します。 DeflaterOutputStream(OutputStream out デフレーター def boolean syncFlush) : 指定されたコンプレッサー フラッシュ モードとデフォルトのバッファ サイズで新しい出力ストリームを作成します。 DeflaterOutputStream(OutputStream out デフレーター def int サイズ) : 指定されたコンプレッサーとバッファ サイズで新しい出力ストリームを作成します。 DeflaterOutputStream(OutputStream out デフレーター def int size boolean syncFlush) : 指定されたコンプレッサー バッファ サイズとフラッシュ モードで新しい出力ストリームを作成します。
方法:
    void close() : 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 
    保護された void deflate() : Writes next block of compressed data to the output stream.
      Syntax :  protected void deflate() throws IOException   Throws:   IOException 
    ボイド終了() : Finishes writing compressed data to the output stream without closing the underlying stream.
      Syntax :  public void finish() throws IOException   Throws:   IOException 
    ボイドフラッシュ() : 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  ();      }   }   
注記: ここでは file2.txt を読み取ることができないため、プログラムの出力はオンライン IDE では表示されません。 クイズの作成