Class CipherOutputStreamImpl

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public abstract class CipherOutputStreamImpl extends CipherOutputStream
A CipherOutputStream is composed of an OutputStream and a cipher so that write() methods process the written data with the cipher, and the output of the cipher is in turn written to the underlying OutputStream. The cipher must be fully initialized before being used by a CipherInputStream.

For example, if the cipher is initialized for encryption, the CipherOutputStream will encrypt the data before writing the encrypted data to the underlying stream.

Note: this class does not close the underlying stream on a close.

  • Field Details

    • algorithmName

      protected final String algorithmName
    • isApprovedMode

      protected final boolean isApprovedMode
    • out

      protected OutputStream out
    • oneByte

      protected final byte[] oneByte
  • Constructor Details

    • CipherOutputStreamImpl

      protected CipherOutputStreamImpl(String algorithmName, OutputStream out)
  • Method Details

    • write

      public void write(int b) throws IOException
      Writes the specified byte to this output stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes from the specified byte array to this output stream.

      The write method of CipherOutputStream calls the write method of three arguments with the three arguments b, 0, and b.length.

      Overrides:
      write in class OutputStream
      Parameters:
      b - the data.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • flush

      public void flush() throws IOException
      Flushes this output stream by forcing any buffered output bytes that have already been processed by the encapsulated cipher object to be written out.

      Any bytes buffered by the encapsulated cipher and waiting to be processed by it will not be written out. For example, if the encapsulated cipher is a block cipher, and the total number of bytes written using one of the write methods is less than the cipher's block size, no bytes will be written out.

      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an I/O error occurs.
    • getInstance

      public static CipherOutputStream getInstance(OutputStream out, StreamCipher cipher)
    • getInstance

      public static CipherOutputStream getInstance(OutputStream out, BufferedBlockCipher cipher)
    • getInstance

      public static CipherOutputStream getInstance(OutputStream out, AEADCipher cipher)