Class StreamCompressor
java.lang.Object
org.apache.commons.compress.archivers.zip.StreamCompressor
- All Implemented Interfaces:
Closeable,AutoCloseable
Encapsulates a
Deflater and crc calculator, handling multiple types of output streams. Currently ZipEntry.DEFLATED and
ZipEntry.STORED are the only supported compression methods.- Since:
- 1.10
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static StreamCompressorcreate(int compressionLevel, ScatterGatherBackingStore bs) Creates a stream compressor with the given compression level.static StreamCompressorCreates a stream compressor with the default compression level.voiddeflate(InputStream source, int method) Deflate the given source using the supplied compression methodlongGets the number of bytes read from the source streamlongThe number of bytes written to the output for the last entrylonggetCrc32()The crc32 of the last deflated filelongThe total number of bytes written to the output for all filesvoidwriteCounted(byte[] data) voidwriteCounted(byte[] data, int offset, int length) protected abstract voidwriteOut(byte[] data, int offset, int length)
-
Method Details
-
create
Creates a stream compressor with the given compression level.- Parameters:
compressionLevel- TheDeflatercompression levelbs- The ScatterGatherBackingStore to receive output- Returns:
- A stream compressor
-
create
Creates a stream compressor with the default compression level.- Parameters:
bs- The ScatterGatherBackingStore to receive output- Returns:
- A stream compressor
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
deflate
Deflate the given source using the supplied compression method- Parameters:
source- The source to compressmethod- The #ZipArchiveEntry compression method- Throws:
IOException- When failures happen
-
getBytesRead
Gets the number of bytes read from the source stream- Returns:
- The number of bytes read, never negative
-
getBytesWrittenForLastEntry
The number of bytes written to the output for the last entry- Returns:
- The number of bytes, never negative
-
getCrc32
The crc32 of the last deflated file- Returns:
- the crc32
-
getTotalBytesWritten
The total number of bytes written to the output for all files- Returns:
- The number of bytes, never negative
-
writeCounted
- Throws:
IOException
-
writeCounted
- Throws:
IOException
-
writeOut
- Throws:
IOException
-