Top Description Inners Fields Constructors Methods
org.bouncycastle.openpgp

public Class PGPCanonicalizedDataGenerator

extends Object
implements StreamGenerator
Class Inheritance
All Implemented Interfaces
org.bouncycastle.openpgp.StreamGenerator
Imports
java.io.BufferedOutputStream, .ByteArrayOutputStream, .File, .FileNotFoundException, .FileOutputStream, .IOException, .OutputStream, java.util.Date, org.bouncycastle.util.Arrays

Generator for producing filtered literal data packets which are automatically canonicalized.

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

A PGPCanonicalizedDataGenerator is usually used to wrap the OutputStream obtained from a PGPEncryptedDataGenerator or a PGPCompressedDataGenerator.

Once literal data 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
pack-priv static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final String
CONSOLE

The special name indicating a "for your eyes only" packet.

private PGPLiteralDataGenerator
public static final Date
NOW

The special time for a modification time of "now" or the present time.

private boolean
public static final char
TEXT

Format tag for textual literal data

public static final char
UTF8

Format tag for UTF-8 encoded textual literal data

Constructor Summary

AccessConstructor and Description
public
PGPCanonicalizedDataGenerator()

Constructs a generator for literal data objects.

public
PGPCanonicalizedDataGenerator(boolean
true to use PGP 2.6.x compatible format.
oldFormat
)

Constructs a generator for literal data objects, specifying to use new or old (PGP 2.6.x compatible) format.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements org.bouncycastle.openpgp.StreamGenerator.close.

Close the literal data packet - this is equivalent to calling close on the stream returned by the open() method.

public OutputStream
open(OutputStream
the underlying output stream to write the literal data packet to.
out
,
char
the format of the literal data that will be written to the output stream (one of TEXT or UTF8).
format
,
String
the name of the "file" to encode in the literal data object.
name
,
Date
the time of last modification we want stored.
modificationTime
)

Open a literal data packet, returning a stream to store the data inside the packet.

public OutputStream
open(OutputStream
the underlying output stream to write the literal data packet to.
out
,
char
the format of the literal data that will be written to the output stream (one of TEXT or UTF8).
format
,
String
the name of the "file" to encode in the literal data object.
name
,
Date
the time of last modification we want stored.
modificationTime
,
File backingFile)

Open a literal data packet, returning a stream to store the data inside the packet.

public OutputStream

Returns:

the output stream to write data to.
open
(OutputStream
the underlying output stream to write the literal data packet to.
out
,
char
the format of the literal data that will be written to the output stream (one of TEXT or UTF8).
format
,
String
the name of the "file" to encode in the literal data object.
name
,
Date
the time of last modification we want stored (will be stored to second level precision).
modificationTime
,
byte[]
a buffer to use to buffer and write partial packets. The returned stream takes ownership of the buffer.
buffer
)

Open a literal data packet, returning a stream to store the data inside the packet as an indefinite-length stream.

public OutputStream

Returns:

the output stream to write data to.
open
(OutputStream
the underlying output stream to write the literal data packet to.
out
,
char
the format of the literal data that will be written to the output stream (one of TEXT or UTF8).
format
,
File
the file to determine the filename from.
file
)

Open a literal data packet for the passed in File object, returning an output stream for saving the file contents.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CONSOLEback to summary
public static final String CONSOLE

The special name indicating a "for your eyes only" packet.

lGenback to summary
private PGPLiteralDataGenerator lGen
NOWback to summary
public static final Date NOW

The special time for a modification time of "now" or the present time.

oldFormatback to summary
private boolean oldFormat
TEXTback to summary
public static final char TEXT

Format tag for textual literal data

UTF8back to summary
public static final char UTF8

Format tag for UTF-8 encoded textual literal data

Constructor Detail

PGPCanonicalizedDataGeneratorback to summary
public PGPCanonicalizedDataGenerator()

Constructs a generator for literal data objects.

PGPCanonicalizedDataGeneratorback to summary
public PGPCanonicalizedDataGenerator(boolean oldFormat)

Constructs a generator for literal data objects, specifying to use new or old (PGP 2.6.x compatible) format.

This can be used for compatibility with PGP 2.6.x.

Parameters
oldFormat:boolean

true to use PGP 2.6.x compatible format.

Method Detail

closeback to summary
public void close() throws IOException

Implements org.bouncycastle.openpgp.StreamGenerator.close.

Close the literal data packet - this is equivalent to calling close on the stream returned by the open() method.

openback to summary
public OutputStream open(OutputStream out, char format, String name, Date modificationTime) throws IOException

Open a literal data packet, returning a stream to store the data inside the packet.

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

the underlying output stream to write the literal data packet to.

format:char

the format of the literal data that will be written to the output stream (one of TEXT or UTF8).

name:String

the name of the "file" to encode in the literal data object.

modificationTime:Date

the time of last modification we want stored.

openback to summary
public OutputStream open(OutputStream out, char format, String name, Date modificationTime, File backingFile) throws IOException

Open a literal data packet, returning a stream to store the data inside the packet.

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

the underlying output stream to write the literal data packet to.

format:char

the format of the literal data that will be written to the output stream (one of TEXT or UTF8).

name:String

the name of the "file" to encode in the literal data object.

modificationTime:Date

the time of last modification we want stored.

openback to summary
public OutputStream open(OutputStream out, char format, String name, Date modificationTime, byte[] buffer) throws IOException

Open a literal data packet, returning a stream to store the data inside the packet as an indefinite-length stream. The stream is written out as a series of partial packets with a chunk size determined by 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.

Parameters
out:OutputStream

the underlying output stream to write the literal data packet to.

format:char

the format of the literal data that will be written to the output stream (one of TEXT or UTF8).

name:String

the name of the "file" to encode in the literal data object.

modificationTime:Date

the time of last modification we want stored (will be stored to second level precision).

buffer:byte[]

a buffer to use to buffer and write partial packets. The returned stream takes ownership of the buffer.

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.
openback to summary
public OutputStream open(OutputStream out, char format, File file) throws IOException

Open a literal data packet for the passed in File object, returning an output stream for saving the file contents.

This method configures the generator to store the file contents in a single literal data packet, taking the filename and modification time from the file, but does not store the actual file data.

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

the underlying output stream to write the literal data packet to.

format:char

the format of the literal data that will be written to the output stream (one of TEXT or UTF8).

file:File

the file to determine the filename from.

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 PGPCanonicalizedDataGenerator.ArrayCRLFGeneratorStream

extends CRLFGeneratorStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final char
private final PGPLiteralDataGenerator
private final Date
private final String
private final OutputStream
Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
crlfOut

Constructor Summary

AccessConstructor and Description
public
ArrayCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
write

Field Detail

formatback to summary
private final char format
lGenback to summary
private final PGPLiteralDataGenerator lGen
modificationTimeback to summary
private final Date modificationTime
nameback to summary
private final String name
outback to summary
private final OutputStream out

Constructor Detail

ArrayCRLFGeneratorStreamback to summary
public ArrayCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime)

Method Detail

closeback to summary
public void close() throws IOException

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.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

pack-priv Class PGPCanonicalizedDataGenerator.CRLFGeneratorStream

extends OutputStream
Class Inheritance
Known Direct Subclasses
org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.FileCRLFGeneratorStream, org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.IndefiniteCRLFGeneratorStream, org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.ArrayCRLFGeneratorStream

Field Summary

Modifier and TypeField and Description
protected final OutputStream
private final boolean
private int

Constructor Summary

AccessConstructor and Description
public
CRLFGeneratorStream(OutputStream crlfOut, boolean isBinary)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.

Inherited from java.io.OutputStream:
flushnullOutputStreamwritewrite

Field Detail

crlfOutback to summary
protected final OutputStream crlfOut
isBinaryback to summary
private final boolean isBinary
lastBback to summary
private int lastB

Constructor Detail

CRLFGeneratorStreamback to summary
public CRLFGeneratorStream(OutputStream crlfOut, boolean isBinary)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.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.
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
org.bouncycastle.openpgp back to summary

private final Class PGPCanonicalizedDataGenerator.ErasableOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public byte[]
Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

ErasableOutputStreamback to summary
public ErasableOutputStream()

Method Detail

eraseback to summary
public void erase()
getBufback to summary
public byte[] getBuf()
org.bouncycastle.openpgp back to summary

private Class PGPCanonicalizedDataGenerator.FileCRLFGeneratorStream

extends CRLFGeneratorStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final File
private final char
private final PGPLiteralDataGenerator
private final Date
private final String
private final OutputStream
Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
crlfOut

Constructor Summary

AccessConstructor and Description
public
FileCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime, File backingFile)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
write

Field Detail

backingFileback to summary
private final File backingFile
formatback to summary
private final char format
lGenback to summary
private final PGPLiteralDataGenerator lGen
modificationTimeback to summary
private final Date modificationTime
nameback to summary
private final String name
outback to summary
private final OutputStream out

Constructor Detail

FileCRLFGeneratorStreamback to summary
public FileCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime, File backingFile) throws FileNotFoundException

Method Detail

closeback to summary
public void close() throws IOException

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.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 PGPCanonicalizedDataGenerator.IndefiniteCRLFGeneratorStream

extends CRLFGeneratorStream
Class Inheritance

Field Summary

Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
crlfOut

Constructor Summary

AccessConstructor and Description
public
IndefiniteCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime, byte[] buffer)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with this stream.

Inherited from org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream:
write

Constructor Detail

IndefiniteCRLFGeneratorStreamback to summary
public IndefiniteCRLFGeneratorStream(OutputStream out, PGPLiteralDataGenerator sGen, char format, String name, Date modificationTime, byte[] buffer) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides org.bouncycastle.openpgp.PGPCanonicalizedDataGenerator.CRLFGeneratorStream.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.