Clase Java.util.zip.DeflaterInputStream en Java Esta clase implementa un filtro de flujo de salida para comprimir datos en el formato de compresión 'deflate'. También se utiliza como base para otros tipos de filtros de compresión como GZIPOutputStream. Constructores y descripción
DeflaterOutputStream(OutputStream fuera):
Crea un nuevo flujo de salida con un compresor y un tamaño de búfer predeterminados.
DeflaterOutputStream(OutputStream out boolean syncFlush):
Crea un nuevo flujo de salida con un compresor predeterminado, un tamaño de búfer predeterminado y el modo de descarga especificado.
DefladorOutputStream(OutputStream out Deflater def):
Crea un nuevo flujo de salida con el compresor especificado y un tamaño de búfer predeterminado.
DeflaterOutputStream(OutputStream out Deflater def boolean syncFlush):
Crea un nuevo flujo de salida con el modo de descarga del compresor especificado y un tamaño de búfer predeterminado.
DeflaterOutputStream(OutputStream out Deflater def int size):
Crea un nuevo flujo de salida con el compresor y el tamaño de búfer especificados.
DeflaterOutputStream(OutputStream out Deflater def int tamaño booleano syncFlush):
Crea un nuevo flujo de salida con el tamaño de búfer del compresor y el modo de descarga especificados. Métodos:
cierre vacío() :
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
desinflado vacío protegido() :
Writes next block of compressed data to the output stream.
Finishes writing compressed data to the output stream without closing the underlying stream.
Syntax : public void finish() throws IOException Throws: IOException
descarga vacía() :
Flushes the compressed output stream.
Syntax : public void flush() throws IOException Overrides: flush in class FilterOutputStream Throws: IOException
escritura nula (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
escritura nula (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 DeflaterOutputStreamimportjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.zip.DeflaterOutputStream;classDeflaterOutputStreamDemo{publicstaticvoidmain(String[]args)throwsIOException{FileOutputStreamfos=newFileOutputStream('file2.txt');//Assign FileOutputStream to DeflaterOutputStreamDeflaterOutputStreamdos=newDeflaterOutputStream(fos);//write it into DeflaterOutputStreamfor(inti=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 streamdos.finish();//fos is not closed//writing some data on filefos.write('G');//Writes remaining compressed data to the output stream// closes the underlying stream.dos.close();}}
Nota: La salida del programa no será visible en el IDE en línea ya que el archivo 2.txt no se puede leer aquí. Crear cuestionario