code: public final void encryptStream(SecretKey sharedKey, InputStream input, OutputStream output) throws IOException {
          logger.entry();
          CipherOutputStream cipherOutput = null;
          byte[] buffer = new byte[2048];
          try {
              logger.debug("Creating a special output stream to do the work...");
              cipherOutput = encryptionOutputStream(sharedKey, output);
  
              logger.debug("Reading from the input and writing to the encrypting output stream...");
              // Can't use IOUtils.copy(input, cipherOutput) here because need to purge buffer later...
              int bytesRead;
              while ((bytesRead = input.read(buffer)) != -1) {
                  cipherOutput.write(buffer, 0, bytesRead);
              }
              cipherOutput.flush();
          } finally {
              logger.debug("Purging any plaintext hanging around in memory...");
              Arrays.fill(buffer, (byte) 0);
  
              if (cipherOutput != null) cipherOutput.close();
          }
          logger.exit();
      }
docs: This method encrypts a byte stream using a shared key.
  
  @param sharedKey The shared key used for the encryption.
  @param input The byte stream to be encrypted.
  @param output The encrypted output stream.
  @throws java.io.IOException Unable to encrypt the stream.