javax.crypto

Class CipherOutputStream

public class CipherOutputStream extends FilterOutputStream

A filtered output stream that transforms data written to it with a {@link Cipher} before sending it to the underlying output stream.
Constructor Summary
CipherOutputStream(OutputStream out, Cipher cipher)
Create a new cipher output stream.
protected CipherOutputStream(OutputStream out)
Create a cipher output stream with no cipher.
Method Summary
voidclose()
Close this output stream, and the sink output stream.
voidflush()
Flush any pending output.
voidwrite(int b)
Write a single byte to the output stream.
voidwrite(byte[] buf)
Write a byte array to the output stream.
voidwrite(byte[] buf, int off, int len)
Write a portion of a byte array to the output stream.

Constructor Detail

CipherOutputStream

public CipherOutputStream(OutputStream out, Cipher cipher)
Create a new cipher output stream. The cipher argument must have already been initialized.

Parameters: out The sink for transformed data. cipher The cipher to transform data with.

CipherOutputStream

protected CipherOutputStream(OutputStream out)
Create a cipher output stream with no cipher.

Parameters: out The sink for transformed data.

Method Detail

close

public void close()
Close this output stream, and the sink output stream.

This method will first invoke the {@link Cipher#doFinal()} method of the underlying {@link Cipher}, and writes the output of that method to the sink output stream.

Throws: IOException If an I/O error occurs, or if an error is caused by finalizing the transformation.

flush

public void flush()
Flush any pending output.

Throws: IOException If an I/O error occurs.

write

public void write(int b)
Write a single byte to the output stream.

Parameters: b The next byte.

Throws: IOException If an I/O error occurs, or if the underlying cipher is not in the correct state to transform data.

write

public void write(byte[] buf)
Write a byte array to the output stream.

Parameters: buf The next bytes.

Throws: IOException If an I/O error occurs, or if the underlying cipher is not in the correct state to transform data.

write

public void write(byte[] buf, int off, int len)
Write a portion of a byte array to the output stream.

Parameters: buf The next bytes. off The offset in the byte array to start. len The number of bytes to write.

Throws: IOException If an I/O error occurs, or if the underlying cipher is not in the correct state to transform data.