Class StreamCompressor
- java.lang.Object
-
- org.apache.commons.compress.archivers.zip.StreamCompressor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public abstract class StreamCompressor extends java.lang.Object implements java.io.Closeable
Encapsulates aDeflaterand CRC calculator, handling multiple types of output streams. CurrentlyZipEntry.DEFLATEDandZipEntry.STOREDare the only supported compression methods.- Since:
- 1.10
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()static StreamCompressorcreate(int compressionLevel, ScatterGatherBackingStore bs)Creates a stream compressor with the given compression level.static StreamCompressorcreate(ScatterGatherBackingStore bs)Creates a stream compressor with the default compression level.voiddeflate(java.io.InputStream source, int method)Deflates the given source using the supplied compression methodlonggetBytesRead()Gets the number of bytes read from the source streamlonggetBytesWrittenForLastEntry()Gets the number of bytes written to the output for the last entrylonggetCrc32()Gets the CRC-32 of the last deflated filelonggetTotalBytesWritten()Gets the total number of bytes written to the output for all filesvoidwriteCounted(byte[] data)Writes the specified byte array to the output stream.voidwriteCounted(byte[] data, int offset, int length)Writeslenbytes from the specified byte array starting at offsetoffto the output stream.protected abstract voidwriteOut(byte[] data, int offset, int length)Writeslenbytes from the specified byte array starting at offsetoffto the output stream.
-
-
-
Method Detail
-
create
public static StreamCompressor create(int compressionLevel, ScatterGatherBackingStore bs)
Creates a stream compressor with the given compression level.- Parameters:
compressionLevel- TheDeflatercompression levelbs- The ScatterGatherBackingStore to receive output- Returns:
- A stream compressor
-
create
public static StreamCompressor create(ScatterGatherBackingStore bs)
Creates a stream compressor with the default compression level.- Parameters:
bs- The ScatterGatherBackingStore to receive output- Returns:
- A stream compressor
-
close
public void close() throws java.io.IOException
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
deflate
public void deflate(java.io.InputStream source, int method) throws java.io.IOException
Deflates the given source using the supplied compression method- Parameters:
source- The source to compressmethod- The #ZipArchiveEntry compression method- Throws:
java.io.IOException- When failures happen
-
getBytesRead
public long getBytesRead()
Gets the number of bytes read from the source stream- Returns:
- The number of bytes read, never negative
-
getBytesWrittenForLastEntry
public long getBytesWrittenForLastEntry()
Gets the number of bytes written to the output for the last entry- Returns:
- The number of bytes, never negative
-
getCrc32
public long getCrc32()
Gets the CRC-32 of the last deflated file- Returns:
- the CRC-32
-
getTotalBytesWritten
public long getTotalBytesWritten()
Gets the total number of bytes written to the output for all files- Returns:
- The number of bytes, never negative
-
writeCounted
public void writeCounted(byte[] data) throws java.io.IOException
Writes the specified byte array to the output stream.- Parameters:
data- the data.- Throws:
java.io.IOException- if an I/O error occurs.
-
writeCounted
public void writeCounted(byte[] data, int offset, int length) throws java.io.IOException
Writeslenbytes from the specified byte array starting at offsetoffto the output stream.- Parameters:
data- the data.offset- the start offset in the data.length- the number of bytes to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
writeOut
protected abstract void writeOut(byte[] data, int offset, int length) throws java.io.IOException
Writeslenbytes from the specified byte array starting at offsetoffto the output stream.- Parameters:
data- the data.offset- the start offset in the data.length- the number of bytes to write.- Throws:
java.io.IOException- if an I/O error occurs.
-
-