Package javax.crypto
Class CipherOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
javax.crypto.CipherOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class CipherOutputStream extends FilterOutputStream
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.
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors Modifier Constructor Description protectedCipherOutputStream(OutputStream os)Creates a newCipherOutputStreaminstance for anOutputStreamwithout a cipher.CipherOutputStream(OutputStream os, Cipher c)Creates a newCipherOutputStreaminstance for anOutputStreamand aCipher. -
Method Summary
Modifier and Type Method Description voidclose()Close this cipher output stream.voidflush()Flushes this cipher output stream.voidwrite(byte[] b, int off, int len)Writes thelenbytes from bufferbstarting at offsetoffto this cipher output stream.voidwrite(int b)Writes the single byte to this cipher output stream.Methods inherited from class java.io.OutputStream
write
-
Constructor Details
-
CipherOutputStream
Creates a newCipherOutputStreaminstance for anOutputStreamand aCipher.- Parameters:
os- the output stream to write data to.c- the cipher to process the data with.
-
CipherOutputStream
Creates a newCipherOutputStreaminstance for anOutputStreamwithout a cipher.A
NullCipheris created to process the data.- Parameters:
os- the output stream to write the data to.
-
-
Method Details
-
write
Writes the single byte to this cipher output stream.- Overrides:
writein classFilterOutputStream- Parameters:
b- the byte to write.- Throws:
IOException- if an error occurs.
-
write
Writes thelenbytes from bufferbstarting at offsetoffto this cipher output stream.- Overrides:
writein classFilterOutputStream- Parameters:
b- the buffer.off- the offset to start at.len- the number of bytes.- Throws:
IOException- if an error occurs.
-
flush
Flushes this cipher output stream.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException- if an error occurs
-
close
Close this cipher output stream.On the underlying cipher
doFinalwill 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.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException- if an error occurs.
-