public final class GzipSink extends java.lang.Object implements Sink
flush()
immediately compresses all currently-buffered data;
this early compression may be less effective than compression performed
without flushing.
This is equivalent to using Deflater
with the sync flush option.
This class does not offer any partial flush mechanism. For best performance,
only call flush()
when application behavior requires it.
Modifier and Type | Field and Description |
---|---|
private boolean |
closed |
private java.util.zip.CRC32 |
crc
Checksum calculated for the compressed body.
|
private java.util.zip.Deflater |
deflater
The deflater used to compress the body.
|
private DeflaterSink |
deflaterSink
The deflater sink takes care of moving data between decompressed source and
compressed sink buffers.
|
private BufferedSink |
sink
Sink into which the GZIP format is written.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Pushes all buffered bytes to their final destination and releases the
resources held by this sink.
|
java.util.zip.Deflater |
deflater()
Returns the
Deflater . |
void |
flush()
Pushes all buffered bytes to their final destination.
|
Timeout |
timeout()
Returns the timeout for this sink.
|
private void |
updateCrc(Buffer buffer,
long byteCount)
Updates the CRC with the given bytes.
|
void |
write(Buffer source,
long byteCount)
Removes
byteCount bytes from source and appends them to this. |
private void |
writeFooter() |
private void |
writeHeader() |
private final BufferedSink sink
private final java.util.zip.Deflater deflater
private final DeflaterSink deflaterSink
private boolean closed
private final java.util.zip.CRC32 crc
public GzipSink(Sink sink)
public void write(Buffer source, long byteCount) throws java.io.IOException
Sink
byteCount
bytes from source
and appends them to this.public void flush() throws java.io.IOException
Sink
public Timeout timeout()
Sink
public void close() throws java.io.IOException
Sink
public java.util.zip.Deflater deflater()
Deflater
.
Use it to access stats, dictionary, compression level, etc.private void writeHeader()
private void writeFooter() throws java.io.IOException
java.io.IOException
private void updateCrc(Buffer buffer, long byteCount)