Cryptix OpenPGP

cryptix.message.stream
Class MessageOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycryptix.message.stream.MessageOutputStream
Direct Known Subclasses:
EncryptedMessageOutputStream, LiteralMessageOutputStream, SignedMessageOutputStream

public abstract class MessageOutputStream
extends java.io.OutputStream

A generic stream that encapsulates another stream in some message format.

Version:
$Revision: 1.1 $
Author:
Edwin Woudt

Field Summary
protected  MessageOutputStreamSpi spi
           
 
Constructor Summary
protected MessageOutputStream(MessageOutputStreamSpi spi, java.security.Provider provider, java.lang.String format)
          Create a new MessageOutputStream object containing the given SPI object.
 
Method Summary
 void close()
          Close the stream Sends all data through the underlying stream and then calls the close() method of the underlying stream.
 void flush()
          Flush the stream What flushing does is format specific.
 java.lang.String getFormat()
          Returns the name of the format of this object.
 java.security.Provider getProvider()
          Returns the provider of this object.
 MessageOutputStreamSpi getSpi()
          Return the underlying service provider interface This method should not be called by user applications.
 void init(java.io.OutputStream out, java.security.SecureRandom sr)
          Initializes this outputstream with the given outputstream as underlying stream and the given SecureRandom object.
 void setAttribute(java.lang.String name, java.lang.Object attr)
          Set a format specific attribute.
 void write(byte[] b)
          Write a complete bytearray to the stream
 void write(byte[] b, int off, int len)
          Write the specified part of a bytearray to the stream.
 void write(int b)
          Write a single byte to the stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spi

protected final MessageOutputStreamSpi spi
Constructor Detail

MessageOutputStream

protected MessageOutputStream(MessageOutputStreamSpi spi,
                              java.security.Provider provider,
                              java.lang.String format)
Create a new MessageOutputStream object containing the given SPI object.

Method Detail

getProvider

public final java.security.Provider getProvider()
Returns the provider of this object.


getFormat

public final java.lang.String getFormat()
Returns the name of the format of this object.


init

public final void init(java.io.OutputStream out,
                       java.security.SecureRandom sr)
                throws java.lang.IllegalStateException,
                       java.io.IOException,
                       MessageStreamException
Initializes this outputstream with the given outputstream as underlying stream and the given SecureRandom object.

Parameters:
out - The underlying outputstream this stream will write results to.
sr - A SecureRandom object used for any randomness needed.
Throws:
java.lang.IllegalStateException - if this message has been initialized before.
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

setAttribute

public final void setAttribute(java.lang.String name,
                               java.lang.Object attr)
                        throws java.lang.IllegalStateException,
                               java.lang.IllegalArgumentException,
                               MessageStreamException
Set a format specific attribute.

Parameters:
name - a name identifying the attribute
attr - the attribute itself
Throws:
java.lang.IllegalStateException - if this message has not been initialized before.
java.lang.IllegalArgumentException - if the attribute is not supported or the given object does not have the right type.
MessageStreamException - on a variety of format specific problems.

write

public final void write(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException,
                        MessageStreamException
Write the specified part of a bytearray to the stream.

Parameters:
b - the data
off - the starting point of the write operation
len - how many bytes to write
Throws:
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

write

public final void write(byte[] b)
                 throws java.io.IOException,
                        MessageStreamException
Write a complete bytearray to the stream

Parameters:
b - the data
Throws:
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

write

public final void write(int b)
                 throws java.io.IOException,
                        MessageStreamException
Write a single byte to the stream

Parameters:
b - the byte to write
Throws:
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

flush

public final void flush()
                 throws java.io.IOException,
                        MessageStreamException
Flush the stream

What flushing does is format specific. The general contract is that as much bytes as possible are written to the underlying datastream, but no guarantees are given about any buffers left. The reason for this is because cryptographic protocols usually work on specific blocksizes and there usually are only handlers (padding) for incomplete blocks at the end of the stream.

This method should call the flush() method of the underlying outputstream after it is done.

Throws:
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

close

public final void close()
                 throws java.io.IOException,
                        MessageStreamException
Close the stream

Sends all data through the underlying stream and then calls the close() method of the underlying stream.

Throws:
java.io.IOException - on a general IOException that is not format specific.
MessageStreamException - on a variety of format specific problems.

getSpi

public final MessageOutputStreamSpi getSpi()
Return the underlying service provider interface

This method should not be called by user applications.


Cryptix OpenPGP

Copyright (C) 1999-2003 The Cryptix Foundation Ltd.