Top Description Inners Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public abstract Class StreamCompressor

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.apache.commons.compress.archivers.zip.StreamCompressor.DataOutputCompressor, org.apache.commons.compress.archivers.zip.StreamCompressor.OutputStreamCompressor, org.apache.commons.compress.archivers.zip.StreamCompressor.ScatterGatherBackingStoreCompressor, org.apache.commons.compress.archivers.zip.StreamCompressor.SeekableByteChannelCompressor
Imports
java.io.Closeable, .DataOutput, .IOException, .InputStream, .OutputStream, java.nio.ByteBuffer, java.nio.channels.SeekableByteChannel, java.util.zip.CRC32, .Deflater, .ZipEntry, org.apache.commons.compress.parallel.ScatterGatherBackingStore

Encapsulates a Deflater and crc calculator, handling multiple types of output streams. Currently java.util.zip.ZipEntry#DEFLATED and java.util.zip.ZipEntry#STORED are the only supported compression methods.
Since
1.10

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private final CRC32
private final Deflater
private static final int
private final byte[]
private final byte[]
private long
private long
private long

Constructor Summary

AccessConstructor and Description
pack-priv
StreamCompressor(final Deflater deflater)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
pack-priv static StreamCompressor

Returns:

A stream compressor
create
(final DataOutput
The DataOutput to receive output
os
,
final Deflater
The deflater to use for the compressor
deflater
)

Creates a stream compressor with the given compression level.

public static StreamCompressor

Returns:

A stream compressor
create
(final int
The Deflater compression level
compressionLevel
,
final ScatterGatherBackingStore
The ScatterGatherBackingStore to receive output
bs
)

Creates a stream compressor with the given compression level.

pack-priv static StreamCompressor

Returns:

A stream compressor
create
(final OutputStream
The stream to receive output
os
)

Creates a stream compressor with the default compression level.

pack-priv static StreamCompressor

Returns:

A stream compressor
create
(final OutputStream
The stream to receive output
os
,
final Deflater
The deflater to use
deflater
)

Creates a stream compressor with the given compression level.

public static StreamCompressor

Returns:

A stream compressor
create
(final ScatterGatherBackingStore
The ScatterGatherBackingStore to receive output
bs
)

Creates a stream compressor with the default compression level.

pack-priv static StreamCompressor

Returns:

A stream compressor
create
(final SeekableByteChannel
The SeekableByteChannel to receive output
os
,
final Deflater
The deflater to use for the compressor
deflater
)

Creates a stream compressor with the given compression level.

pack-priv void
public void
deflate(final InputStream
The source to compress
source
,
final int
The #ZipArchiveEntry compression method
method
)

Deflate the given source using the supplied compression method

private void
pack-priv void
public long

Returns:

The number of bytes read, never negative
getBytesRead
()

Gets the number of bytes read from the source stream

public long

Returns:

The number of bytes, never negative
getBytesWrittenForLastEntry
()

The number of bytes written to the output for the last entry

public long

Returns:

the crc32
getCrc32
()

The crc32 of the last deflated file

public long

Returns:

The number of bytes, never negative
getTotalBytesWritten
()

The total number of bytes written to the output for all files

pack-priv void
pack-priv long

Returns:

the number of bytes written to the stream this time
write
(final byte[]
the byte array to write
b
,
final int
the start position to write from
offset
,
final int
the number of bytes to write
length
,
final int
the comrpession method to use
method
)

Writes bytes to ZIP entry.

public void
writeCounted(final byte[] data)

public void
writeCounted(final byte[] data, final int offset, final int length)

private void
writeDeflated(final byte[] b, final int offset, final int length)

protected abstract void
writeOut(byte[] data, int offset, int length)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
crcback to summary
private final CRC32 crc
defback to summary
private final Deflater def
DEFLATER_BLOCK_SIZEback to summary
private static final int DEFLATER_BLOCK_SIZE
outputBufferback to summary
private final byte[] outputBuffer
readerBufback to summary
private final byte[] readerBuf
sourcePayloadLengthback to summary
private long sourcePayloadLength
totalWrittenToOutputStreamback to summary
private long totalWrittenToOutputStream
writtenToOutputStreamForLastEntryback to summary
private long writtenToOutputStreamForLastEntry

Constructor Detail

StreamCompressorback to summary
pack-priv StreamCompressor(final Deflater deflater)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
createback to summary
pack-priv static StreamCompressor create(final DataOutput os, final Deflater deflater)

Creates a stream compressor with the given compression level.

Parameters
os:DataOutput

The DataOutput to receive output

deflater:Deflater

The deflater to use for the compressor

Returns:StreamCompressor

A stream compressor

createback to summary
public static StreamCompressor create(final int compressionLevel, final ScatterGatherBackingStore bs)

Creates a stream compressor with the given compression level.

Parameters
compressionLevel:int

The Deflater compression level

bs:ScatterGatherBackingStore

The ScatterGatherBackingStore to receive output

Returns:StreamCompressor

A stream compressor

createback to summary
pack-priv static StreamCompressor create(final OutputStream os)

Creates a stream compressor with the default compression level.

Parameters
os:OutputStream

The stream to receive output

Returns:StreamCompressor

A stream compressor

createback to summary
pack-priv static StreamCompressor create(final OutputStream os, final Deflater deflater)

Creates a stream compressor with the given compression level.

Parameters
os:OutputStream

The stream to receive output

deflater:Deflater

The deflater to use

Returns:StreamCompressor

A stream compressor

createback to summary
public static StreamCompressor create(final ScatterGatherBackingStore bs)

Creates a stream compressor with the default compression level.

Parameters
bs:ScatterGatherBackingStore

The ScatterGatherBackingStore to receive output

Returns:StreamCompressor

A stream compressor

createback to summary
pack-priv static StreamCompressor create(final SeekableByteChannel os, final Deflater deflater)

Creates a stream compressor with the given compression level.

Parameters
os:SeekableByteChannel

The SeekableByteChannel to receive output

deflater:Deflater

The deflater to use for the compressor

Returns:StreamCompressor

A stream compressor

Since
1.13
deflateback to summary
pack-priv void deflate() throws IOException
deflateback to summary
public void deflate(final InputStream source, final int method) throws IOException

Deflate the given source using the supplied compression method

Parameters
source:InputStream

The source to compress

method:int

The #ZipArchiveEntry compression method

Exceptions
IOException:
When failures happen
deflateUntilInputIsNeededback to summary
private void deflateUntilInputIsNeeded() throws IOException
flushDeflaterback to summary
pack-priv void flushDeflater() throws IOException
getBytesReadback to summary
public long getBytesRead()

Gets the number of bytes read from the source stream

Returns:long

The number of bytes read, never negative

getBytesWrittenForLastEntryback to summary
public long getBytesWrittenForLastEntry()

The number of bytes written to the output for the last entry

Returns:long

The number of bytes, never negative

getCrc32back to summary
public long getCrc32()

The crc32 of the last deflated file

Returns:long

the crc32

getTotalBytesWrittenback to summary
public long getTotalBytesWritten()

The total number of bytes written to the output for all files

Returns:long

The number of bytes, never negative

resetback to summary
pack-priv void reset()
writeback to summary
pack-priv long write(final byte[] b, final int offset, final int length, final int method) throws IOException

Writes bytes to ZIP entry.

Parameters
b:byte[]

the byte array to write

offset:int

the start position to write from

length:int

the number of bytes to write

method:int

the comrpession method to use

Returns:long

the number of bytes written to the stream this time

Exceptions
IOException:
on error
writeCountedback to summary
public void writeCounted(final byte[] data) throws IOException
writeCountedback to summary
public void writeCounted(final byte[] data, final int offset, final int length) throws IOException
writeDeflatedback to summary
private void writeDeflated(final byte[] b, final int offset, final int length) throws IOException
writeOutback to summary
protected abstract void writeOut(byte[] data, int offset, int length) throws IOException
org.apache.commons.compress.archivers.zip back to summary

private final Class StreamCompressor.DataOutputCompressor

extends StreamCompressor
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final DataOutput

Constructor Summary

AccessConstructor and Description
pack-priv
DataOutputCompressor(final Deflater deflater, final DataOutput raf)

Method Summary

Modifier and TypeMethod and Description
protected void
writeOut(final byte[] data, final int offset, final int length)

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Inherited from org.apache.commons.compress.archivers.zip.StreamCompressor:
closecreatecreatecreatecreatecreatecreatedeflatedeflateflushDeflatergetBytesReadgetBytesWrittenForLastEntrygetCrc32getTotalBytesWrittenresetwritewriteCountedwriteCounted

Field Detail

rafback to summary
private final DataOutput raf

Constructor Detail

DataOutputCompressorback to summary
pack-priv DataOutputCompressor(final Deflater deflater, final DataOutput raf)

Method Detail

writeOutback to summary
protected void writeOut(final byte[] data, final int offset, final int length) throws IOException

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Annotations
@Override
org.apache.commons.compress.archivers.zip back to summary

private final Class StreamCompressor.OutputStreamCompressor

extends StreamCompressor
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final OutputStream

Constructor Summary

AccessConstructor and Description
pack-priv
OutputStreamCompressor(final Deflater deflater, final OutputStream os)

Method Summary

Modifier and TypeMethod and Description
protected void
writeOut(final byte[] data, final int offset, final int length)

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Inherited from org.apache.commons.compress.archivers.zip.StreamCompressor:
closecreatecreatecreatecreatecreatecreatedeflatedeflateflushDeflatergetBytesReadgetBytesWrittenForLastEntrygetCrc32getTotalBytesWrittenresetwritewriteCountedwriteCounted

Field Detail

osback to summary
private final OutputStream os

Constructor Detail

OutputStreamCompressorback to summary
pack-priv OutputStreamCompressor(final Deflater deflater, final OutputStream os)

Method Detail

writeOutback to summary
protected void writeOut(final byte[] data, final int offset, final int length) throws IOException

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Annotations
@Override
org.apache.commons.compress.archivers.zip back to summary

private final Class StreamCompressor.ScatterGatherBackingStoreCompressor

extends StreamCompressor
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ScatterGatherBackingStore

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
writeOut(final byte[] data, final int offset, final int length)

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Inherited from org.apache.commons.compress.archivers.zip.StreamCompressor:
closecreatecreatecreatecreatecreatecreatedeflatedeflateflushDeflatergetBytesReadgetBytesWrittenForLastEntrygetCrc32getTotalBytesWrittenresetwritewriteCountedwriteCounted

Field Detail

bsback to summary
private final ScatterGatherBackingStore bs

Constructor Detail

ScatterGatherBackingStoreCompressorback to summary
pack-priv ScatterGatherBackingStoreCompressor(final Deflater deflater, final ScatterGatherBackingStore bs)

Method Detail

writeOutback to summary
protected void writeOut(final byte[] data, final int offset, final int length) throws IOException

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Annotations
@Override
org.apache.commons.compress.archivers.zip back to summary

private final Class StreamCompressor.SeekableByteChannelCompressor

extends StreamCompressor
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final SeekableByteChannel

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
writeOut(final byte[] data, final int offset, final int length)

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Inherited from org.apache.commons.compress.archivers.zip.StreamCompressor:
closecreatecreatecreatecreatecreatecreatedeflatedeflateflushDeflatergetBytesReadgetBytesWrittenForLastEntrygetCrc32getTotalBytesWrittenresetwritewriteCountedwriteCounted

Field Detail

channelback to summary
private final SeekableByteChannel channel

Constructor Detail

SeekableByteChannelCompressorback to summary
pack-priv SeekableByteChannelCompressor(final Deflater deflater, final SeekableByteChannel channel)

Method Detail

writeOutback to summary
protected void writeOut(final byte[] data, final int offset, final int length) throws IOException

Implements abstract org.apache.commons.compress.archivers.zip.StreamCompressor.writeOut.

Annotations
@Override