Top Description Fields Constructors Methods
org.bouncycastle.bcpg

public Class BCPGOutputStream

extends OutputStream
implements PacketTags, CompressionAlgorithmTags
Class Inheritance
All Implemented Interfaces
org.bouncycastle.bcpg.CompressionAlgorithmTags, org.bouncycastle.bcpg.PacketTags
Known Direct Subclasses
org.bouncycastle.openpgp.PGPEncryptedDataGenerator.ClosableBCPGOutputStream
Imports
java.io.IOException, .OutputStream, org.bouncycastle.util.Arrays

Basic output stream.

Field Summary

Modifier and TypeField and Description
private static final int
pack-priv OutputStream
private byte[]
private int
private int
private int
private boolean

Constructor Summary

AccessConstructor and Description
public
BCPGOutputStream(OutputStream
output stream to write encoded data to.
out
)

Base constructor - generate a PGP protocol encoding with old-style packets whenever there is an alternative for backwards compatibility.

public
BCPGOutputStream(OutputStream
output stream to write encoded data to.
out
,
boolean
true if use new format packets, false if backwards compatible preferred.
newFormatOnly
)

Base constructor specifying whether or not to use packets in the new format wherever possible.

public
BCPGOutputStream(OutputStream out, int
the packet tag for the object.
tag
)

Create a stream representing an old style partial object.

public
BCPGOutputStream(OutputStream out, int tag, long length, boolean oldFormat)

Create a stream representing a general packet.

public
BCPGOutputStream(OutputStream out, int tag, long length)

public
BCPGOutputStream(OutputStream
output stream to write to.
out
,
int
packet tag.
tag
,
byte[]
size of chunks making up the packet.
buffer
)

Create a new style partial input stream buffered into chunks.

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
finish()

Finish writing out the current packet without closing the underlying stream.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flush the underlying stream.
private void
partialFlush(boolean isLast)

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
bytes
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
private void
writeHeader(int tag, boolean oldPackets, boolean partial, long bodyLen)

private void
writeNewPacketLength(long bodyLen)

public void
public void
pack-priv void
writePacket(int tag, byte[] body)

pack-priv void
writePacket(int tag, byte[] body, boolean oldFormat)

private void
writePartial(byte b)

private void
writePartial(byte[] buf, int off, int len)

Inherited from java.io.OutputStream:
nullOutputStreamwrite

Field Detail

BUF_SIZE_POWERback to summary
private static final int BUF_SIZE_POWER
outback to summary
pack-priv OutputStream out
partialBufferback to summary
private byte[] partialBuffer
partialBufferLengthback to summary
private int partialBufferLength
partialOffsetback to summary
private int partialOffset
partialPowerback to summary
private int partialPower
useOldFormatback to summary
private boolean useOldFormat

Constructor Detail

BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out)

Base constructor - generate a PGP protocol encoding with old-style packets whenever there is an alternative for backwards compatibility.

Parameters
out:OutputStream

output stream to write encoded data to.

BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out, boolean newFormatOnly)

Base constructor specifying whether or not to use packets in the new format wherever possible.

Parameters
out:OutputStream

output stream to write encoded data to.

newFormatOnly:boolean

true if use new format packets, false if backwards compatible preferred.

BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out, int tag) throws IOException

Create a stream representing an old style partial object.

Parameters
tag:int

the packet tag for the object.

BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out, int tag, long length, boolean oldFormat) throws IOException

Create a stream representing a general packet.

BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out, int tag, long length) throws IOException
BCPGOutputStreamback to summary
public BCPGOutputStream(OutputStream out, int tag, byte[] buffer) throws IOException

Create a new style partial input stream buffered into chunks.

Parameters
out:OutputStream

output stream to write to.

tag:int

packet tag.

buffer:byte[]

size of chunks making up the packet.

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.
finishback to summary
public void finish() throws IOException

Finish writing out the current packet without closing the underlying stream.

flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flush the underlying stream.

Exceptions
IOException:

Doc from java.io.OutputStream.flush.

if an I/O error occurs.

partialFlushback to summary
private void partialFlush(boolean isLast) throws IOException
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.
writeback to summary
public void write(byte[] bytes, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
bytes:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
writeHeaderback to summary
private void writeHeader(int tag, boolean oldPackets, boolean partial, long bodyLen) throws IOException
writeNewPacketLengthback to summary
private void writeNewPacketLength(long bodyLen) throws IOException
writeObjectback to summary
public void writeObject(BCPGObject o) throws IOException
writePacketback to summary
public void writePacket(ContainedPacket p) throws IOException
writePacketback to summary
pack-priv void writePacket(int tag, byte[] body) throws IOException
writePacketback to summary
pack-priv void writePacket(int tag, byte[] body, boolean oldFormat) throws IOException
writePartialback to summary
private void writePartial(byte b) throws IOException
writePartialback to summary
private void writePartial(byte[] buf, int off, int len) throws IOException