Top Description Inners Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPCompressedDataGenerator

extends Object
implements CompressionAlgorithmTags, StreamGenerator
Class Inheritance
All Implemented Interfaces
org.bouncycastle.openpgp.StreamGenerator, org.bouncycastle.bcpg.CompressionAlgorithmTags
Imports
java.io.IOException, .OutputStream, java.util.zip.Deflater, .DeflaterOutputStream, org.bouncycastle.apache.bzip2.CBZip2OutputStream, org.bouncycastle.bcpg.BCPGOutputStream, .CompressionAlgorithmTags, .PacketTags

Generator for producing compressed data packets.

A PGPCompressedDataGenerator is used by invoking one of the open functions to create an OutputStream that raw data can be supplied to for compression:

A PGPCompressedDataGenerator is usually used to wrap the OutputStream obtained from a PGPEncryptedDataGenerator (i.e. to compress data prior to encrypting it).

Raw data is not typically written directly to the OutputStream obtained from a PGPCompressedDataGenerator. The OutputStream is usually wrapped by a PGPLiteralDataGenerator, which encodes the raw data prior to compression.

Once data for compression has been written to the constructed OutputStream, writing of the object stream is completed by closing the OutputStream obtained from the #open() method, or equivalently invoking close() on this generator.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private int
private int
private OutputStream
private BCPGOutputStream

Constructor Summary

AccessConstructor and Description
public
PGPCompressedDataGenerator(int
the identifier of the compression algorithm to use.
algorithm
)

Construct a new compressed data generator.

public
PGPCompressedDataGenerator(int
the identifier of the compression algorithm to use.
algorithm
,
int
the Deflater compression level to use.
compression
)

Construct a new compressed data generator.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements org.bouncycastle.openpgp.StreamGenerator.close.

Close the compressed object - this is equivalent to calling close on the stream returned by the open() method.
private void
public OutputStream

Returns:

OutputStream
open
(OutputStream
underlying OutputStream to be used.
out
)

Return an OutputStream which will save the data being written to the compressed object.

public OutputStream

Returns:

the output stream to write data to.
open
(OutputStream
the stream to write compressed packets to.
out
,
byte[]
a buffer to use to buffer and write partial packets. The returned stream takes ownership of the buffer and will use it to buffer plaintext data for compression.
buffer
)

Return an OutputStream which will compress the data as it is written to it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private int algorithm
compressionback to summary
private int compression
dOutback to summary
private OutputStream dOut
pkOutback to summary
private BCPGOutputStream pkOut

Constructor Detail

PGPCompressedDataGeneratorback to summary
public PGPCompressedDataGenerator(int algorithm)

Construct a new compressed data generator.

Parameters
algorithm:int

the identifier of the compression algorithm to use.

PGPCompressedDataGeneratorback to summary
public PGPCompressedDataGenerator(int algorithm, int compression)

Construct a new compressed data generator.

Parameters
algorithm:int

the identifier of the compression algorithm to use.

compression:int

the Deflater compression level to use.

Method Detail

closeback to summary
public void close() throws IOException

Implements org.bouncycastle.openpgp.StreamGenerator.close.

Close the compressed object - this is equivalent to calling close on the stream returned by the open() method.

doOpenback to summary
private void doOpen() throws IOException
openback to summary
public OutputStream open(OutputStream out) throws IOException

Return an OutputStream which will save the data being written to the compressed object.

The stream created can be closed off by either calling close() on the stream or close() on the generator. Closing the returned stream does not close off the OutputStream parameter out.

Parameters
out:OutputStream

underlying OutputStream to be used.

Returns:OutputStream

OutputStream

openback to summary
public OutputStream open(OutputStream out, byte[] buffer) throws IOException, PGPException

Return an OutputStream which will compress the data as it is written to it. The stream will be written out in chunks (partials) according to the size of the passed in buffer.

The stream created can be closed off by either calling close() on the stream or close() on the generator. Closing the returned stream does not close off the OutputStream parameter out.

Note

if the buffer is not a power of 2 in length only the largest power of 2 bytes worth of the buffer will be used.

Note

using this may break compatibility with RFC 1991 compliant tools. Only recent OpenPGP implementations are capable of accepting these streams.

Parameters
out:OutputStream

the stream to write compressed packets to.

buffer:byte[]

a buffer to use to buffer and write partial packets. The returned stream takes ownership of the buffer and will use it to buffer plaintext data for compression.

Returns:OutputStream

the output stream to write data to.

Exceptions
IOException:
if an error occurs writing stream header information to the provider output stream.
IllegalStateException:
if this generator already has an open OutputStream.
org.bouncycastle.openpgp back to summary

private Class PGPCompressedDataGenerator.SafeCBZip2OutputStream

extends CBZip2OutputStream
Class Inheritance

Field Summary

Inherited from org.bouncycastle.apache.bzip2.CBZip2OutputStream:
CLEARMASKDEPTH_THRESHGREATER_ICOSTLESSER_ICOSTSETMASKSMALL_THRESH

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.bouncycastle.apache.bzip2.CBZip2OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.
Inherited from org.bouncycastle.apache.bzip2.CBZip2OutputStream:
finalizefinishflushhbMakeCodeLengthswrite

Constructor Detail

SafeCBZip2OutputStreamback to summary
public SafeCBZip2OutputStream(OutputStream output) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides org.bouncycastle.apache.bzip2.CBZip2OutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.OutputStream.close.

Closes this output stream and releases any system resources associated with this stream. The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

Exceptions
IOException:
if an I/O error occurs.
org.bouncycastle.openpgp back to summary

private Class PGPCompressedDataGenerator.SafeDeflaterOutputStream

extends DeflaterOutputStream
Class Inheritance

Field Summary

Inherited from java.util.zip.DeflaterOutputStream:
bufdef

Constructor Summary

AccessConstructor and Description
public
SafeDeflaterOutputStream(OutputStream output, int compression, boolean nowrap)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.util.zip.DeflaterOutputStream.close.

Implements java.io.Closeable.close.

Writes remaining compressed data to the output stream and closes the underlying stream.
Inherited from java.util.zip.DeflaterOutputStream:
deflatefinishflushwritewrite

Constructor Detail

SafeDeflaterOutputStreamback to summary
public SafeDeflaterOutputStream(OutputStream output, int compression, boolean nowrap)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.util.zip.DeflaterOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.util.zip.DeflaterOutputStream.close.

Writes remaining compressed data to the output stream and closes the underlying stream.

Exceptions
IOException:
if an I/O error has occurred