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 TypeMethodDescriptionvoid
close()
static StreamCompressor
create
(int compressionLevel, ScatterGatherBackingStore bs) Creates a stream compressor with the given compression level.static StreamCompressor
Creates a stream compressor with the default compression level.void
deflate
(InputStream source, int method) Deflates the given source using the supplied compression methodlong
Gets the number of bytes read from the source streamlong
Gets the number of bytes written to the output for the last entrylong
getCrc32()
Gets the CRC-32 of the last deflated filelong
Gets the total number of bytes written to the output for all filesvoid
writeCounted
(byte[] data) Writes the specified byte array to the output stream.void
writeCounted
(byte[] data, int offset, int length) Writeslen
bytes from the specified byte array starting at offsetoff
to the output stream.protected abstract void
writeOut
(byte[] data, int offset, int length) Writeslen
bytes from the specified byte array starting at offsetoff
to the output stream.
-
Method Details
-
create
Creates a stream compressor with the given compression level.- Parameters:
compressionLevel
- TheDeflater
compression 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
deflate
Deflates 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
Gets the number of bytes written to the output for the last entry- Returns:
- The number of bytes, never negative
-
getCrc32
Gets the CRC-32 of the last deflated file- Returns:
- the CRC-32
-
getTotalBytesWritten
Gets the total number of bytes written to the output for all files- Returns:
- The number of bytes, never negative
-
writeCounted
Writes the specified byte array to the output stream.- Parameters:
data
- the data.- Throws:
IOException
- if an I/O error occurs.
-
writeCounted
Writeslen
bytes from the specified byte array starting at offsetoff
to the output stream.- Parameters:
data
- the data.offset
- the start offset in the data.length
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.
-
writeOut
Writeslen
bytes from the specified byte array starting at offsetoff
to the output stream.- Parameters:
data
- the data.offset
- the start offset in the data.length
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.
-