Java.util.zip.DeflaterInputStream class in Java
This class implements an output stream filter for compressing data in the “deflate” compression format. It is also used as the basis for other types of compression filters, such as GZIPOutputStream.
Constructors and Description
- DeflaterOutputStream(OutputStream out) : Creates a new output stream with a default compressor and buffer size.
- DeflaterOutputStream(OutputStream out, boolean syncFlush) : Creates a new output stream with a default compressor, a default buffer size and the specified flush mode.
- DeflaterOutputStream(OutputStream out, Deflater def) : Creates a new output stream with the specified compressor and a default buffer size.
- DeflaterOutputStream(OutputStream out, Deflater def, boolean syncFlush) : Creates a new output stream with the specified compressor, flush mode and a default buffer size.
- DeflaterOutputStream(OutputStream out, Deflater def, int size) : Creates a new output stream with the specified compressor and buffer size.
- DeflaterOutputStream(OutputStream out, Deflater def, int size, boolean syncFlush) : Creates a new output stream with the specified compressor, buffer size and flush mode.
Methods:
- 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
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" );
DeflaterOutputStream dos = new DeflaterOutputStream(fos);
for ( int i = 0 ; i < 10 ; i++)
{
dos.write(i);
}
dos.flush();
dos.finish();
fos.write( 'G' );
dos.close();
}
}
|
Note: Output of the program will not be visible on online IDE as file2.txt can not be read here.
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
12 Sep, 2023
Like Article
Save Article