public abstract class StreamCompressor
extends java.lang.Object
implements java.io.Closeable
Deflater
and crc calculator, handling multiple types of output streams.
Currently ZipEntry.DEFLATED
and ZipEntry.STORED
are the only
supported compression methods.Modifier and Type | Class and Description |
---|---|
private static class |
StreamCompressor.DataOutputCompressor |
private static class |
StreamCompressor.OutputStreamCompressor |
private static class |
StreamCompressor.ScatterGatherBackingStoreCompressor |
private static class |
StreamCompressor.SeekableByteChannelCompressor |
Modifier and Type | Field and Description |
---|---|
private static int |
BUFFER_SIZE |
private java.util.zip.CRC32 |
crc |
private java.util.zip.Deflater |
def |
private static int |
DEFLATER_BLOCK_SIZE |
private byte[] |
outputBuffer |
private byte[] |
readerBuf |
private long |
sourcePayloadLength |
private long |
totalWrittenToOutputStream |
private long |
writtenToOutputStreamForLastEntry |
Constructor and Description |
---|
StreamCompressor(java.util.zip.Deflater deflater) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
(package private) static StreamCompressor |
create(java.io.DataOutput os,
java.util.zip.Deflater deflater)
Create a stream compressor with the given compression level.
|
static StreamCompressor |
create(int compressionLevel,
ScatterGatherBackingStore bs)
Create a stream compressor with the given compression level.
|
(package private) static StreamCompressor |
create(java.io.OutputStream os)
Create a stream compressor with the default compression level.
|
(package private) static StreamCompressor |
create(java.io.OutputStream os,
java.util.zip.Deflater deflater)
Create a stream compressor with the given compression level.
|
static StreamCompressor |
create(ScatterGatherBackingStore bs)
Create a stream compressor with the default compression level.
|
(package private) static StreamCompressor |
create(java.nio.channels.SeekableByteChannel os,
java.util.zip.Deflater deflater)
Create a stream compressor with the given compression level.
|
(package private) void |
deflate() |
void |
deflate(java.io.InputStream source,
int method)
Deflate the given source using the supplied compression method
|
private void |
deflateUntilInputIsNeeded() |
(package private) void |
flushDeflater() |
long |
getBytesRead()
Return the number of bytes read from the source stream
|
long |
getBytesWrittenForLastEntry()
The number of bytes written to the output for the last entry
|
long |
getCrc32()
The crc32 of the last deflated file
|
long |
getTotalBytesWritten()
The total number of bytes written to the output for all files
|
(package private) void |
reset() |
(package private) long |
write(byte[] b,
int offset,
int length,
int method)
Writes bytes to ZIP entry.
|
void |
writeCounted(byte[] data) |
void |
writeCounted(byte[] data,
int offset,
int length) |
private void |
writeDeflated(byte[] b,
int offset,
int length) |
protected abstract void |
writeOut(byte[] data,
int offset,
int length) |
private static final int DEFLATER_BLOCK_SIZE
private final java.util.zip.Deflater def
private final java.util.zip.CRC32 crc
private long writtenToOutputStreamForLastEntry
private long sourcePayloadLength
private long totalWrittenToOutputStream
private static final int BUFFER_SIZE
private final byte[] outputBuffer
private final byte[] readerBuf
static StreamCompressor create(java.io.OutputStream os, java.util.zip.Deflater deflater)
os
- The stream to receive outputdeflater
- The deflater to usestatic StreamCompressor create(java.io.OutputStream os)
os
- The stream to receive outputstatic StreamCompressor create(java.io.DataOutput os, java.util.zip.Deflater deflater)
os
- The DataOutput to receive outputdeflater
- The deflater to use for the compressorstatic StreamCompressor create(java.nio.channels.SeekableByteChannel os, java.util.zip.Deflater deflater)
os
- The SeekableByteChannel to receive outputdeflater
- The deflater to use for the compressorpublic static StreamCompressor create(int compressionLevel, ScatterGatherBackingStore bs)
compressionLevel
- The Deflater
compression levelbs
- The ScatterGatherBackingStore to receive outputpublic static StreamCompressor create(ScatterGatherBackingStore bs)
bs
- The ScatterGatherBackingStore to receive outputpublic long getCrc32()
public long getBytesRead()
public long getBytesWrittenForLastEntry()
public long getTotalBytesWritten()
public void deflate(java.io.InputStream source, int method) throws java.io.IOException
source
- The source to compressmethod
- The #ZipArchiveEntry compression methodjava.io.IOException
- When failures happenlong write(byte[] b, int offset, int length, int method) throws java.io.IOException
b
- the byte array to writeoffset
- the start position to write fromlength
- the number of bytes to writemethod
- the comrpession method to usejava.io.IOException
- on errorvoid reset()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
void flushDeflater() throws java.io.IOException
java.io.IOException
private void writeDeflated(byte[] b, int offset, int length) throws java.io.IOException
java.io.IOException
private void deflateUntilInputIsNeeded() throws java.io.IOException
java.io.IOException
void deflate() throws java.io.IOException
java.io.IOException
public void writeCounted(byte[] data) throws java.io.IOException
java.io.IOException
public void writeCounted(byte[] data, int offset, int length) throws java.io.IOException
java.io.IOException
protected abstract void writeOut(byte[] data, int offset, int length) throws java.io.IOException
java.io.IOException