FileDocCategorySizeDatePackage
GZIPOutputStream.javaAPI DocAndroid 1.5 API3532Wed May 06 22:41:02 BST 2009java.util.zip

GZIPOutputStream

public class GZIPOutputStream extends DeflaterOutputStream
The {@code GZIPOutputStream} class is used to write data to a stream in the GZIP storage format.
since
Android 1.0

Fields Summary
protected CRC32
crc
The checksum algorithm used when treating uncompressed data.
Constructors Summary
public GZIPOutputStream(OutputStream os)
Construct a new {@code GZIPOutputStream} to write data in GZIP format to the underlying stream.

param
os the {@code OutputStream} to write data to.
throws
IOException if an {@code IOException} occurs.
since
Android 1.0


                                                                   
         
        this(os, BUF_SIZE);
    
public GZIPOutputStream(OutputStream os, int size)
Construct a new {@code GZIPOutputStream} to write data in GZIP format to the underlying stream. Set the internal compression buffer to size {@code size}.

param
os the {@code OutputStream} to write to.
param
size the internal buffer size.
throws
IOException if an {@code IOException} occurs.
since
Android 1.0

        super(os, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
        writeShort(GZIPInputStream.GZIP_MAGIC);
        out.write(Deflater.DEFLATED);
        out.write(0); // flags
        writeLong(0); // mod time
        out.write(0); // extra flags
        out.write(0); // operating system
    
Methods Summary
public voidfinish()
Indicates to the stream that all data has been written out, and any GZIP terminal data can now be written.

throws
IOException if an {@code IOException} occurs.
since
Android 1.0

        super.finish();
        writeLong(crc.getValue());
        writeLong(crc.tbytes);
    
public voidwrite(byte[] buffer, int off, int nbytes)

        super.write(buffer, off, nbytes);
        crc.update(buffer, off, nbytes);
    
private longwriteLong(long i)

        // Write out the long value as an unsigned int
        out.write((int) (i & 0xFF));
        out.write((int) (i >> 8) & 0xFF);
        out.write((int) (i >> 16) & 0xFF);
        out.write((int) (i >> 24) & 0xFF);
        return i;
    
private intwriteShort(int i)

        out.write(i & 0xFF);
        out.write((i >> 8) & 0xFF);
        return i;