Class PGPLiteralDataGenerator
- java.lang.Object
-
- org.bouncycastle.openpgp.PGPLiteralDataGenerator
-
public class PGPLiteralDataGenerator extends java.lang.ObjectGenerator for producing literal data packets.A PGPLiteralData is used by invoking one of the open functions to create an OutputStream that raw data can be supplied to for encoding:
- If the length of the data to be written is known in advance, use
open(OutputStream, char, String, long, Date)to create a packet containing a single literal data object. - If the length of the data is unknown, use
open(OutputStream, char, String, Date, byte[])to create a packet consisting of a series of literal data objects (partials).
A PGPLiteralDataGenerator is usually used to wrap the OutputStream
obtainedfrom aPGPEncryptedDataGeneratoror aPGPCompressedDataGenerator.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 invokingclose()on this generator. - If the length of the data to be written is known in advance, use
-
-
Field Summary
Fields Modifier and Type Field Description static charBINARYFormat tag for binary literal datastatic java.lang.StringCONSOLEThe special name indicating a "for your eyes only" packet.static java.util.DateNOWThe special time for a modification time of "now" or the present time.static charTEXTFormat tag for textual literal datastatic charUTF8Format tag for UTF-8 encoded textual literal data
-
Constructor Summary
Constructors Constructor Description PGPLiteralDataGenerator()Constructs a generator for literal data objects.PGPLiteralDataGenerator(boolean oldFormat)Constructs a generator for literal data objects, specifying to use new or old (PGP 2.6.x compatible) format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the literal data packet - this is equivalent to calling close on the stream returned by the open() method.java.io.OutputStreamopen(java.io.OutputStream out, char format, java.io.File file)Open a literal data packet for the passed in File object, returning an output stream for saving the file contents.java.io.OutputStreamopen(java.io.OutputStream out, char format, java.lang.String name, long length, java.util.Date modificationTime)Open a literal data packet, returning a stream to store the data inside the packet.java.io.OutputStreamopen(java.io.OutputStream out, char format, java.lang.String name, java.util.Date modificationTime, byte[] buffer)Open a literal data packet, returning a stream to store the data inside the packet as an indefinite-length stream.
-
-
-
Field Detail
-
BINARY
public static final char BINARY
Format tag for binary literal data- See Also:
- Constant Field Values
-
TEXT
public static final char TEXT
Format tag for textual literal data- See Also:
- Constant Field Values
-
UTF8
public static final char UTF8
Format tag for UTF-8 encoded textual literal data- See Also:
- Constant Field Values
-
CONSOLE
public static final java.lang.String CONSOLE
The special name indicating a "for your eyes only" packet.- See Also:
- Constant Field Values
-
NOW
public static final java.util.Date NOW
The special time for a modification time of "now" or the present time.
-
-
Constructor Detail
-
PGPLiteralDataGenerator
public PGPLiteralDataGenerator()
Constructs a generator for literal data objects.
-
PGPLiteralDataGenerator
public PGPLiteralDataGenerator(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-trueto use PGP 2.6.x compatible format.
-
-
Method Detail
-
open
public java.io.OutputStream open(java.io.OutputStream out, char format, java.lang.String name, long length, java.util.Date modificationTime) throws java.io.IOExceptionOpen 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- the underlying output stream to write the literal data packet to.format- the format of the literal data that will be written to the output stream (one ofBINARY,TEXTorUTF8).name- the name of the "file" to encode in the literal data object.length- the length of the data that will be written.modificationTime- the time of last modification we want stored.- Throws:
java.io.IOException
-
open
public java.io.OutputStream open(java.io.OutputStream out, char format, java.lang.String name, java.util.Date modificationTime, byte[] buffer) throws java.io.IOExceptionOpen 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- the underlying output stream to write the literal data packet to.format- the format of the literal data that will be written to the output stream (one ofBINARY,TEXTorUTF8).name- the name of the "file" to encode in the literal data object.modificationTime- the time of last modification we want stored (will be stored to second level precision).buffer- a buffer to use to buffer and write partial packets. The returned stream takes ownership of the buffer.- Returns:
- the output stream to write data to.
- Throws:
java.io.IOException- if an error occurs writing stream header information to the provider output stream.java.lang.IllegalStateException- if this generator already has an open OutputStream.
-
open
public java.io.OutputStream open(java.io.OutputStream out, char format, java.io.File file) throws java.io.IOExceptionOpen 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- the underlying output stream to write the literal data packet to.format- the format of the literal data that will be written to the output stream (one ofBINARY,TEXTorUTF8).file- the file to determine the length and filename from.- Returns:
- the output stream to write data to.
- Throws:
java.io.IOException- if an error occurs writing stream header information to the provider output stream.java.lang.IllegalStateException- if this generator already has an open OutputStream.
-
close
public void close() throws java.io.IOExceptionClose the literal data packet - this is equivalent to calling close on the stream returned by the open() method.- Throws:
java.io.IOException
-
-