public class

CipherOutputStream

extends FilterOutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ javax.crypto.CipherOutputStream

Class Overview

This class wraps an output stream and a cipher so that write methods send the data through the cipher before writing them to the underlying output stream.

The cipher must be initialized for the requested operation before being used by a CipherOutputStream. For example, if a cipher initialized for encryption is used with a CipherOutputStream, the CipherOutputStream tries to encrypt the data writing it out.

Summary

[Expand]
Inherited Fields
From class java.io.FilterOutputStream
Public Constructors
CipherOutputStream(OutputStream os, Cipher c)
Creates a new CipherOutputStream instance for an OutputStream and a Cipher.
Protected Constructors
CipherOutputStream(OutputStream os)
Creates a new CipherOutputStream instance for an OutputStream without a cipher.
Public Methods
void close()
Close this cipher output stream.
void flush()
Flushes this cipher output stream.
void write(byte[] b)
Writes the buffer of bytes to this cipher output stream.
void write(int b)
Writes the single byte to this cipher output stream.
void write(byte[] b, int off, int len)
Writes the len bytes from buffer b starting at offset off to this cipher output stream.
[Expand]
Inherited Methods
From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Public Constructors

public CipherOutputStream (OutputStream os, Cipher c)

Since: API Level 1

Creates a new CipherOutputStream instance for an OutputStream and a Cipher.

Parameters
os the output stream to write data to.
c the cipher to process the data with.

Protected Constructors

protected CipherOutputStream (OutputStream os)

Since: API Level 1

Creates a new CipherOutputStream instance for an OutputStream without a cipher.

A NullCipher is created to process the data.

Parameters
os the output stream to write the data to.

Public Methods

public void close ()

Since: API Level 1

Close this cipher output stream.

On the underlying cipher doFinal will be invoked, and any buffered bytes from the cipher are also written out, and the cipher is reset to its initial state. The underlying output stream is also closed.

Throws
IOException if an error occurs.

public void flush ()

Since: API Level 1

Flushes this cipher output stream.

Throws
IOException if an error occurs

public void write (byte[] b)

Since: API Level 1

Writes the buffer of bytes to this cipher output stream.

Parameters
b the buffer of bytes.
Throws
IOException if an error occurs.

public void write (int b)

Since: API Level 1

Writes the single byte to this cipher output stream.

Parameters
b the byte to write.
Throws
IOException if an error occurs.

public void write (byte[] b, int off, int len)

Since: API Level 1

Writes the len bytes from buffer b starting at offset off to this cipher output stream.

Parameters
b the buffer.
off the offset to start at.
len the number of bytes.
Throws
IOException if an error occurs.