Package java.util.zip
Class GZIPOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
java.util.zip.GZIPOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class GZIPOutputStream extends DeflaterOutputStream
The
GZIPOutputStream class is used to write data to a stream in the
GZIP storage format.
Example
Using GZIPOutputStream is a little easier than ZipOutputStream
because GZIP is only for compression, and is not a container for multiple files.
This code creates a GZIP stream, similar to the gzip(1) utility.
OutputStream os = ...
byte[] bytes = ...
GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(os));
try {
zos.write(bytes);
} finally {
zos.close();
}
-
Field Summary
Fields Modifier and Type Field Description protected CRC32crcThe checksum algorithm used when treating uncompressed data.Fields inherited from class java.util.zip.DeflaterOutputStream
buf, defFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors Constructor Description GZIPOutputStream(OutputStream os)Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream.GZIPOutputStream(OutputStream os, boolean syncFlush)Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given flushing behavior (seeDeflaterOutputStream.flush()).GZIPOutputStream(OutputStream os, int bufferSize)Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (seeDeflaterOutputStream.flush()).GZIPOutputStream(OutputStream os, int bufferSize, boolean syncFlush)Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (seeDeflaterOutputStream.flush()). -
Method Summary
Modifier and Type Method Description voidfinish()Indicates to the stream that all data has been written out, and any GZIP terminal data can now be written.voidwrite(byte[] buffer, int off, int nbytes)Write up to nbytes of data from the given buffer, starting at offset off, to the underlying stream in GZIP format.Methods inherited from class java.util.zip.DeflaterOutputStream
close, deflate, flush, writeMethods inherited from class java.io.OutputStream
write
-
Field Details
-
crc
The checksum algorithm used when treating uncompressed data.
-
-
Constructor Details
-
GZIPOutputStream
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream.- Throws:
IOException
-
GZIPOutputStream
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given flushing behavior (seeDeflaterOutputStream.flush()).- Throws:
IOException- Since:
- 1.7
-
GZIPOutputStream
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (seeDeflaterOutputStream.flush()).- Throws:
IOException
-
GZIPOutputStream
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (seeDeflaterOutputStream.flush()).- Throws:
IOException- Since:
- 1.7
-
-
Method Details
-
finish
Indicates to the stream that all data has been written out, and any GZIP terminal data can now be written.- Overrides:
finishin classDeflaterOutputStream- Throws:
IOException- if anIOExceptionoccurs.
-
write
Write up to nbytes of data from the given buffer, starting at offset off, to the underlying stream in GZIP format.- Overrides:
writein classDeflaterOutputStream- Parameters:
buffer- the buffer to write.off- the index of the first byte inbufferto write.nbytes- the number of bytes inbufferto write.- Throws:
IOException- If an error occurs during writing.
-