Top Description Inners Fields Constructors Methods
org.bouncycastle.bcpg

public Class ArmoredOutputStream

extends OutputStream
Class Inheritance
Imports
java.io.IOException, .OutputStream, java.util.ArrayList, .Collections, .Enumeration, .HashMap, .Hashtable, .Iterator, .List, .Map, 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

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

pack-priv

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
)
Deprecated use appropriate methods in Builder instead

Set an additional header entry.

public void
beginClearText(int
hash algorithm
hashAlgorithm
)

Start a clear text signed message - backwards compatibility.

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

Start a clear text signed message.

public static ArmoredOutputStream.Builder
public void
clearHeaders()
Deprecated use appropriate methods in Builder instead.

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 static void
encode(OutputStream out, byte[] data, int len)

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

private static void
encode3(OutputStream out, byte[] data)

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()
Deprecated use Builder#clearHeaders() instead.

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
)
Deprecated use appropriate methods in Builder instead.

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
write(String string)

private void
Inherited from java.io.OutputStream:
nullOutputStreamwritewrite

Field Detail

bufback to summary
pack-priv byte[] buf
bufPtrback to summary
pack-priv int bufPtr
CHARSET_HDRback to summary
public static final String CHARSET_HDR
chunkCountback to summary
pack-priv int chunkCount
clearTextback to summary
pack-priv boolean clearText
COMMENT_HDRback to summary
public static final String COMMENT_HDR
crcback to summary
pack-priv CRC24 crc
DEFAULT_VERSIONback to summary
public static final String DEFAULT_VERSION
encodingTableback to summary
private static final byte[] encodingTable
footerStartback to summary
pack-priv String footerStart
footerTailback to summary
pack-priv String footerTail
HASH_HDRback to summary
public static final String HASH_HDR
headersback to summary
pack-priv final 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
MESSAGE_ID_HDRback to summary
public static final String MESSAGE_ID_HDR
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
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.

ArmoredOutputStreamback to summary
pack-priv ArmoredOutputStream(OutputStream out, ArmoredOutputStream.Builder builder)

Method Detail

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

Deprecated

use appropriate methods in Builder instead

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.

Annotations
@Deprecated
beginClearTextback to summary
public void beginClearText(int hashAlgorithm) throws IOException

Start a clear text signed message - backwards compatibility.

Parameters
hashAlgorithm:int

hash algorithm

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

Start a clear text signed message.

Parameters
hashAlgorithms:int[]

hash algorithms

builderback to summary
public static ArmoredOutputStream.Builder builder()
clearHeadersback to summary
public void clearHeaders()

Deprecated

use appropriate methods in Builder instead.

Remove all headers.

Annotations
@Deprecated
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 static void encode(OutputStream out, byte[] data, int len) throws IOException

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

encode3back to summary
private static void encode3(OutputStream out, byte[] data) 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()

Deprecated

use Builder#clearHeaders() instead.

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

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

Deprecated

use appropriate methods in Builder instead.

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.

Annotations
@Deprecated
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
private void write(String string) throws IOException
writeHeaderEntryback to summary
private void writeHeaderEntry(String name, String value) throws IOException
org.bouncycastle.bcpg back to summary

public Class ArmoredOutputStream.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private final Map<String, List<String>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ArmoredOutputStream.Builder

Returns:

builder
addComment
(String
comment
comment
)

Add the given value as one or more additional

Comment:
private ArmoredOutputStream.Builder

Returns:

builder
addHeader
(String
key
key
,
String
value
value
)

Add a header, splitting it into multiple headers if required (newlines).

public ArmoredOutputStream
build(OutputStream outputStream)

public ArmoredOutputStream.Builder
public ArmoredOutputStream.Builder

Returns:

the current builder instance.
enableCRC
(boolean
true if CRC to be included, false otherwise.
doComputeCRC
)

Enable calculation and inclusion of the CRC check sum (default is true).

private ArmoredOutputStream.Builder

Returns:

builder
replaceHeader
(String
key
key
,
String
value
value
)

Replace all header values for the given key with the given value.

public ArmoredOutputStream.Builder

Returns:

builder
setCharset
(String
charset
charset
)

Replace the

Charset:
public ArmoredOutputStream.Builder

Returns:

builder
setComment
(String
comment
comment
)

Replace the

Comment:
public ArmoredOutputStream.Builder

Returns:

builder
setMessageId
(String
message ID
messageId
)

Replace the

MessageID:
private ArmoredOutputStream.Builder

Returns:

builder
setSingletonHeader
(String
header key
key
,
String
header value
value
)

Set and replace the given header value with a single-line header.

public ArmoredOutputStream.Builder

Returns:

builder
setVersion
(String
version
version
)

Set a

Version:
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

computeCRCSumback to summary
private boolean computeCRCSum
headersback to summary
private final Map<String, List<String>> headers

Constructor Detail

Builderback to summary
private Builder()

Method Detail

addCommentback to summary
public ArmoredOutputStream.Builder addComment(String comment)

Add the given value as one or more additional

Comment:
headers to the already present comments. If the comment contains newlines, multiple headers will be added, one for each newline. If the comment is
null
, this method does nothing.
Parameters
comment:String

comment

Returns:ArmoredOutputStream.Builder

builder

addHeaderback to summary
private ArmoredOutputStream.Builder addHeader(String key, String value)

Add a header, splitting it into multiple headers if required (newlines).

Parameters
key:String

key

value:String

value

Returns:ArmoredOutputStream.Builder

builder

buildback to summary
public ArmoredOutputStream build(OutputStream outputStream)
clearHeadersback to summary
public ArmoredOutputStream.Builder clearHeaders()
enableCRCback to summary
public ArmoredOutputStream.Builder enableCRC(boolean doComputeCRC)

Enable calculation and inclusion of the CRC check sum (default is true).

Parameters
doComputeCRC:boolean

true if CRC to be included, false otherwise.

Returns:ArmoredOutputStream.Builder

the current builder instance.

replaceHeaderback to summary
private ArmoredOutputStream.Builder replaceHeader(String key, String value)

Replace all header values for the given key with the given value. If the value is

null
, existing headers for the given key are removed. The value is split into multiple headers if it contains newlines.
Parameters
key:String

key

value:String

value

Returns:ArmoredOutputStream.Builder

builder

setCharsetback to summary
public ArmoredOutputStream.Builder setCharset(String charset)

Replace the

Charset:
header with the given value.
Parameters
charset:String

charset

Returns:ArmoredOutputStream.Builder

builder

setCommentback to summary
public ArmoredOutputStream.Builder setComment(String comment)

Replace the

Comment:
header field with the given comment. If the comment contains newlines, multiple headers will be added, one for each newline. If the comment is
null
, then the output will contain no comments.
Parameters
comment:String

comment

Returns:ArmoredOutputStream.Builder

builder

setMessageIdback to summary
public ArmoredOutputStream.Builder setMessageId(String messageId)

Replace the

MessageID:
header field with the given messageId.
Parameters
messageId:String

message ID

Returns:ArmoredOutputStream.Builder

builder

setSingletonHeaderback to summary
private ArmoredOutputStream.Builder setSingletonHeader(String key, String value)

Set and replace the given header value with a single-line header. If the value is

null
, this method will remove the header entirely.
Parameters
key:String

header key

value:String

header value

Returns:ArmoredOutputStream.Builder

builder

setVersionback to summary
public ArmoredOutputStream.Builder setVersion(String version)

Set a

Version:
header.

Note

Adding version headers to ASCII armored output is discouraged to minimize metadata.

Parameters
version:String

version

Returns:ArmoredOutputStream.Builder

builder