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
TheGZIPOutputStreamclass is used to write data to a stream in the GZIP storage format.Example
Using
GZIPOutputStreamis a little easier thanZipOutputStreambecause GZIP is only for compression, and is not a container for multiple files. This code creates a GZIP stream, similar to thegzip(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, def
-
Fields 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.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
All Methods Instance Methods Concrete Methods 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, write
-
Methods inherited from class java.io.OutputStream
write
-
-
-
-
Field Detail
-
crc
protected CRC32 crc
The checksum algorithm used when treating uncompressed data.
-
-
Constructor Detail
-
GZIPOutputStream
public GZIPOutputStream(OutputStream os) throws IOException
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream.- Throws:
IOException
-
GZIPOutputStream
public GZIPOutputStream(OutputStream os, boolean syncFlush) throws IOException
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
public GZIPOutputStream(OutputStream os, int bufferSize) throws IOException
Constructs a newGZIPOutputStreamto write data in GZIP format to the given stream with the given internal buffer size.- Throws:
IOException
-
GZIPOutputStream
public GZIPOutputStream(OutputStream os, int bufferSize, boolean syncFlush) throws IOException
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 Detail
-
finish
public void finish() throws IOExceptionIndicates 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
public void write(byte[] buffer, int off, int nbytes) throws IOExceptionWrite 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.
-
-