Android APIs
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, int off, int len)
Writes the len bytes from buffer b starting at offset off to this cipher output stream.
void write(int b)
Writes the single byte 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
From interface java.lang.AutoCloseable

Public Constructors

public CipherOutputStream (OutputStream os, Cipher c)

Added in API level 1

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

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

Protected Constructors

protected CipherOutputStream (OutputStream os)

Added in API level 1

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

A NullCipher is created to process the data.

Parameters
os OutputStream: the output stream to write the data to.

Public Methods

public void close ()

Added in 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 ()

Added in API level 1

Flushes this cipher output stream.

Throws
IOException if an error occurs

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

Added in API level 1

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

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

public void write (int b)

Added in API level 1

Writes the single byte to this cipher output stream.

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