Top Description Fields Constructors Methods
org.bouncycastle.bcpg

public Class ArmoredOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.util.ArrayList, .Enumeration, .Hashtable, .Iterator, .List, org.bouncycastle.util.Strings

Output stream that writes data in ASCII Armored format.

Note 1: close() needs to be called on an ArmoredOutputStream to write the final checksum. flush() will not do this as other classes assume it is always fine to call flush() - it is not though if the checksum gets output. Note 2: as multiple PGP blobs are often written to the same stream, close() does not close the underlying stream.

Field Summary

Modifier and TypeField and Description
pack-priv int[]
pack-priv int
pack-priv int
pack-priv boolean
pack-priv CRC24
private static final byte[]
pack-priv String
pack-priv String
pack-priv Hashtable<String, List<String>>
pack-priv String
pack-priv String
pack-priv int
pack-priv boolean
pack-priv String
pack-priv OutputStream
pack-priv boolean
pack-priv String
pack-priv String
public static final String

Constructor Summary

AccessConstructor and Description
public
ArmoredOutputStream(OutputStream
the OutputStream to wrap.
out
)

Constructs an armored output stream with default headers.

public
ArmoredOutputStream(OutputStream
the OutputStream to wrap.
out
,
Hashtable<String, String>
additional headers that add to or override the default headers.
headers
)

Constructs an armored output stream with default and custom headers.

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(String
the name of the header entry.
name
,
String
the value of the header entry.
value
)

Set an additional header entry.

public void
beginClearText(int...
hash algorithms
hashAlgorithms
)

Start a clear text signed message.

public void
clearHeaders()

Remove all headers.

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Note

close() does not close the underlying stream.

private void
encode(OutputStream out, int[] data, int len)

encode the input data producing a base 64 encoded byte array.

public void
public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out.
public void
resetHeaders()

Reset the headers to only contain a Version string (if one is present)

public void
setHeader(String
the name of the header entry.
name
,
String
the value of the header entry.
value
)

Set an additional header entry.

public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
private void
Inherited from java.io.OutputStream:
nullOutputStreamwritewrite

Field Detail

bufback to summary
pack-priv int[] buf
bufPtrback to summary
pack-priv int bufPtr
chunkCountback to summary
pack-priv int chunkCount
clearTextback to summary
pack-priv boolean clearText
crcback to summary
pack-priv CRC24 crc
encodingTableback to summary
private static final byte[] encodingTable
footerStartback to summary
pack-priv String footerStart
footerTailback to summary
pack-priv String footerTail
headersback to summary
pack-priv Hashtable<String, List<String>> headers
headerStartback to summary
pack-priv String headerStart
headerTailback to summary
pack-priv String headerTail
lastbback to summary
pack-priv int lastb
newLineback to summary
pack-priv boolean newLine
nlback to summary
pack-priv String nl
outback to summary
pack-priv OutputStream out
startback to summary
pack-priv boolean start
typeback to summary
pack-priv String type
versionback to summary
pack-priv String version
VERSION_HDRback to summary
public static final String VERSION_HDR

Constructor Detail

ArmoredOutputStreamback to summary
public ArmoredOutputStream(OutputStream out)

Constructs an armored output stream with default headers.

Parameters
out:OutputStream

the OutputStream to wrap.

ArmoredOutputStreamback to summary
public ArmoredOutputStream(OutputStream out, Hashtable<String, String> headers)

Constructs an armored output stream with default and custom headers.

Parameters
out:OutputStream

the OutputStream to wrap.

headers:Hashtable<String, String>

additional headers that add to or override the default headers.

Method Detail

addHeaderback to summary
public void addHeader(String name, String value)

Set an additional header entry. The current value(s) will continue to exist together with the new one. Adding a null value has no effect.

Parameters
name:String

the name of the header entry.

value:String

the value of the header entry.

beginClearTextback to summary
public void beginClearText(int... hashAlgorithms) throws IOException

Start a clear text signed message.

Parameters
hashAlgorithms:int[]

hash algorithms

clearHeadersback to summary
public void clearHeaders()

Remove all headers.

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Note

close() does not close the underlying stream. So it is possible to write multiple objects using armoring to a single stream.

Exceptions
IOException:

Doc from java.io.OutputStream.close.

if an I/O error occurs.

encodeback to summary
private void encode(OutputStream out, int[] data, int len) throws IOException

encode the input data producing a base 64 encoded byte array.

endClearTextback to summary
public void endClearText()
flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.OutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

Exceptions
IOException:
if an I/O error occurs.
resetHeadersback to summary
public void resetHeaders()

Reset the headers to only contain a Version string (if one is present)

setHeaderback to summary
public void setHeader(String name, String value)

Set an additional header entry. Any current value(s) under the same name will be replaced by the new one. A null value will clear the entry for name.

Parameters
name:String

the name of the header entry.

value:String

the value of the header entry.

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.
writeHeaderEntryback to summary
private void writeHeaderEntry(String name, String value) throws IOException