docs: public OutputStream getOutputStream(File file, Attachment.Encoding encoding) throws
              IOException {
  
          // First, open a stream to the raw bytes on disk.
          // Then, if we have a key assume the file should be encrypted before writing,
          // so wrap the file stream in a stream which encrypts during writing.
          // If the attachment needs encoding, we need to encode the data before it
          // is encrypted, so wrap a stream which will encode (gzip) before passing
          // to encryption stream, or directly to file stream if not encrypting.
          //
          //  User writes [-> Encoding Stream] [-> Encryption Stream] -> write to disk
  
          OutputStream os = FileUtils.openOutputStream(file);
  
          if (key != null) {
  
              try {
  
                  // Create IV
                  byte[] iv = new byte[16];
                  new SecureRandom().nextBytes(iv);
  
                  os = new EncryptedAttachmentOutputStream(os, key, iv);
  
              } catch (InvalidKeyException ex) {
                  // Replace with an IOException as we validate the key when opening
                  // the databases and the key should be the same -- it's therefore
                  // not worth forcing the developer to catch something they can't
                  // fix during file read; generic IOException works better.
                  throw new IOException("Bad key used to write file; check encryption key.", ex);
              } catch (InvalidAlgorithmParameterException ex) {
                  // We are creating what should be a valid IV for AES, 16-bytes.
                  // Therefore this shouldn't happen. Again, the developer cannot
                  // fix it, so wrap in an IOException as we can't write the file.
                  throw new IOException("Bad key used to write file; check encryption key.", ex);
              }
  
          }
  
          switch (encoding) {
              case Plain:
                  break;  // nothing to do
              case Gzip:
                  os = new GZIPOutputStream(os);
          }
  
          return os;
      }