public class CipherOutputStream extends FilterOutputStream
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.
out| Modifier | Constructor and Description |
|---|---|
protected |
CipherOutputStream(OutputStream os)
Creates a new
CipherOutputStream instance for an OutputStream without a cipher. |
|
CipherOutputStream(OutputStream os,
Cipher c)
Creates a new
CipherOutputStream instance for an OutputStream and a Cipher. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
nullOutputStream, writepublic CipherOutputStream(OutputStream os, Cipher c)
CipherOutputStream instance for an OutputStream and a Cipher.os - the output stream to write data to.c - the cipher to process the data with.protected CipherOutputStream(OutputStream os)
CipherOutputStream instance for an OutputStream without a cipher.
A NullCipher is created to process the data.
os - the output stream to write the data to.public void write(int b)
throws IOException
write in class FilterOutputStreamb - the byte to write.IOException - if an error occurs.public void write(byte[] b,
int off,
int len)
throws IOException
len bytes from buffer b starting at offset
off to this cipher output stream.write in class FilterOutputStreamb - the buffer.off - the offset to start at.len - the number of bytes.IOException - if an error occurs.public void flush()
throws IOException
flush in interface Flushableflush in class FilterOutputStreamIOException - if an error occurspublic void close()
throws IOException
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.
close in interface Closeableclose in interface AutoCloseableclose in class FilterOutputStreamIOException - if an error occurs.