Skip to content

Most visited

Recently visited

navigation
Added in API level 1

GZIPOutputStream

public class GZIPOutputStream
extends DeflaterOutputStream

java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ java.util.zip.DeflaterOutputStream
         ↳ java.util.zip.GZIPOutputStream


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();
 }
 

Summary

Fields

protected CRC32 crc

The checksum algorithm used when treating uncompressed data.

Inherited fields

From class java.util.zip.DeflaterOutputStream
From class java.io.FilterOutputStream

Public constructors

GZIPOutputStream(OutputStream os)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream.

GZIPOutputStream(OutputStream os, boolean syncFlush)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given flushing behavior (see flush()).

GZIPOutputStream(OutputStream os, int bufferSize)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given internal buffer size.

GZIPOutputStream(OutputStream os, int bufferSize, boolean syncFlush)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (see flush()).

Public methods

void finish()

Indicates to the stream that all data has been written out, and any GZIP terminal data can now be written.

void write(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.

Inherited methods

From class java.util.zip.DeflaterOutputStream
From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable
From interface java.lang.AutoCloseable

Fields

crc

Added in API level 1
CRC32 crc

The checksum algorithm used when treating uncompressed data.

Public constructors

GZIPOutputStream

Added in API level 1
GZIPOutputStream (OutputStream os)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream.

Parameters
os OutputStream
Throws
IOException

GZIPOutputStream

Added in API level 19
GZIPOutputStream (OutputStream os, 
                boolean syncFlush)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given flushing behavior (see flush()).

Parameters
os OutputStream
syncFlush boolean
Throws
IOException

GZIPOutputStream

Added in API level 1
GZIPOutputStream (OutputStream os, 
                int bufferSize)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given internal buffer size.

Parameters
os OutputStream
bufferSize int
Throws
IOException

GZIPOutputStream

Added in API level 19
GZIPOutputStream (OutputStream os, 
                int bufferSize, 
                boolean syncFlush)

Constructs a new GZIPOutputStream to write data in GZIP format to the given stream with the given internal buffer size and flushing behavior (see flush()).

Parameters
os OutputStream
bufferSize int
syncFlush boolean
Throws
IOException

Public methods

finish

Added in API level 1
void finish ()

Indicates to the stream that all data has been written out, and any GZIP terminal data can now be written.

Throws
IOException if an IOException occurs.

write

Added in API level 1
void write (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.

Parameters
buffer byte: the buffer to write.
off int: the index of the first byte in buffer to write.
nbytes int: the number of bytes in buffer to write.
Throws
IOException
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.