logo

Java.util.zip.DeflaterOutputStream-Klasse in Java

Java.util.zip.DeflaterInputStream-Klasse in Java Diese Klasse implementiert einen Ausgabestreamfilter zum Komprimieren von Daten im Komprimierungsformat „deflate“. Es wird auch als Grundlage für andere Arten von Komprimierungsfiltern wie GZIPOutputStream verwendet. Konstrukteure und Beschreibung
    DeflaterOutputStream(OutputStream out) :Erstellt einen neuen Ausgabestream mit einem Standardkompressor und einer Standardpuffergröße. DeflaterOutputStream(OutputStream out boolean syncFlush) :Erstellt einen neuen Ausgabestream mit einem Standardkompressor, einer Standardpuffergröße und dem angegebenen Flush-Modus. DeflaterOutputStream(OutputStream out Deflater def) :Erstellt einen neuen Ausgabestream mit dem angegebenen Kompressor und einer Standardpuffergröße. DeflaterOutputStream(OutputStream out Deflater def boolean syncFlush) :Erstellt einen neuen Ausgabestream mit dem angegebenen Kompressor-Flush-Modus und einer Standardpuffergröße. DeflaterOutputStream(OutputStream out Deflater def int size) :Erstellt einen neuen Ausgabestream mit der angegebenen Kompressor- und Puffergröße. DeflaterOutputStream(OutputStream out Deflater def int size boolean syncFlush) :Erstellt einen neuen Ausgabestream mit der angegebenen Kompressorpuffergröße und dem angegebenen Flush-Modus.
Methoden:
    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
    protected void deflate() : Writes next block of compressed data to the output stream.
      Syntax :  protected void deflate() throws IOException   Throws:   IOException
    void finish() : 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 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();  } } 
Notiz: Die Ausgabe des Programms ist in der Online-IDE nicht sichtbar, da file2.txt hier nicht gelesen werden kann. Quiz erstellen