Skip to content

Most visited

Recently visited

navigation
Added in API level 1

CipherOutputStream

public class CipherOutputStream
extends FilterOutputStream

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


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

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.

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

CipherOutputStream

Added in API level 1
CipherOutputStream (OutputStream os, 
                Cipher c)

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

CipherOutputStream

Added in API level 1
CipherOutputStream (OutputStream os)

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

close

Added in API level 1
void close ()

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.

flush

Added in API level 1
void flush ()

Flushes this cipher output stream.

Throws
IOException if an error occurs

write

Added in API level 1
void write (byte[] b, 
                int off, 
                int len)

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.

write

Added in API level 1
void write (int b)

Writes the single byte to this cipher output stream.

Parameters
b int: the byte to write.
Throws
IOException if an error occurs.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.